diff --git a/app/Initialize/InitializeMembers.php b/app/Initialize/InitializeMembers.php index 8de43a6b..2798cf38 100644 --- a/app/Initialize/InitializeMembers.php +++ b/app/Initialize/InitializeMembers.php @@ -8,6 +8,7 @@ use App\Country; use App\Member\Member; use App\Region; use App\Nationality; +use App\Fee; class InitializeMembers { @@ -44,11 +45,12 @@ class InitializeMembers { 'email' => $member->email, 'email_parents' => $member->email_parents, 'nami_id' => $member->id, - 'gender_id' => Gender::firstOrFail('nami_id', $member->gender_id)->id, + 'gender_id' => optional(Gender::firstWhere('nami_id', $member->gender_id))->id, 'confession_id' => optional(Confession::firstWhere('nami_id', $member->confession_id))->id, - 'region_id' => Region::firstOrFail('nami_id', $member->region_id)->id, - 'country_id' => Country::firstOrFail('nami_id', $member->country_id)->id, - 'nationality_id' => Nationality::firstOrFail('nami_id', $member->nationality_id)->id, + 'region_id' => Region::where('nami_id', $member->region_id)->firstOrFail()->id, + 'country_id' => Country::where('nami_id', '=', $member->country_id)->firstOrFail()->id, + 'fee_id' => optional(Fee::firstWhere('nami_id', '=', $member->fee_id))->id, + 'nationality_id' => Nationality::where('nami_id', $member->nationality_id)->firstOrFail()->id, ]); }); }); diff --git a/app/Member/Member.php b/app/Member/Member.php index 8cdae6d6..9f0e355c 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -10,7 +10,7 @@ class Member extends Model { use Notifiable; - public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'subscription_id', 'region_id', 'gender_id', 'confession_id']; + public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id']; public $dates = ['joined_at', 'birthday']; @@ -79,8 +79,8 @@ class Member extends Model return $this->hasMany(App\Membership::class); } - public function subscription() + public function fee() { - return $this->belongsTo(App\Subscription::class); + return $this->belongsTo(App\Fee::class); } } diff --git a/database/migrations/2017_07_04_223230_create_members_table.php b/database/migrations/2020_04_12_223230_create_members_table.php similarity index 77% rename from database/migrations/2017_07_04_223230_create_members_table.php rename to database/migrations/2020_04_12_223230_create_members_table.php index d5a364c7..d403c17e 100644 --- a/database/migrations/2017_07_04_223230_create_members_table.php +++ b/database/migrations/2020_04_12_223230_create_members_table.php @@ -14,14 +14,14 @@ class CreateMembersTable extends Migration public function up() { Schema::create('members', function (Blueprint $table) { - $table->increments('id'); + $table->id(); $table->string('firstname'); $table->string('lastname'); $table->string('nickname')->nullable(); - $table->integer('gender_id')->unsigned()->nullable(); - $table->integer('country_id')->unsigned(); + $table->foreignId('gender_id')->nullable()->constrained(); + $table->foreignId('country_id')->constrained(); $table->string('other_country')->nullable(); - $table->integer('confession_id')->unsigned()->nullable(); + $table->foreignId('confession_id')->nullable()->constrained(); $table->date('birthday'); $table->date('joined_at'); $table->boolean('send_newspaper'); @@ -29,7 +29,7 @@ class CreateMembersTable extends Migration $table->string('further_address')->nullable(); $table->string('zip'); $table->string('location'); - $table->string('region_id')->nullable(); + $table->foreignId('region_id')->nullable()->constrained(); $table->string('main_phone')->nullable(); $table->string('mobile_phone')->nullable(); $table->string('work_phone')->nullable(); @@ -37,8 +37,8 @@ class CreateMembersTable extends Migration $table->string('email')->nullable(); $table->string('email_parents')->nullable(); $table->integer('nami_id')->nullable(); - $table->integer('nationality_id')->unsigned(); - $table->integer('subscription_id')->nullable(); + $table->foreignId('nationality_id')->constrained(); + $table->foreignId('fee_id')->constrained(); $table->timestamps(); });