From ad66ef86ab3cb59e6dbbeef5998ae72725ae4a94 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 11 Jul 2021 15:31:34 +0200 Subject: [PATCH] app/Models/CharacterProfession.php: Add specialization relationship --- app/Models/CharacterProfession.php | 6 ++++++ database/factories/CharacterProfessionFactory.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/Models/CharacterProfession.php b/app/Models/CharacterProfession.php index 5eefbd3..456834f 100644 --- a/app/Models/CharacterProfession.php +++ b/app/Models/CharacterProfession.php @@ -21,6 +21,7 @@ class CharacterProfession extends Model protected $fillable = [ 'character_id', 'profession_id', + 'specialization_id', 'skill', ]; @@ -48,6 +49,11 @@ class CharacterProfession extends Model return $this->belongsTo(Profession::class); } + public function specialization() + { + return $this->belongsTo(Spell::class, 'specialization_id'); + } + /** * Get the character that has this profession. */ diff --git a/database/factories/CharacterProfessionFactory.php b/database/factories/CharacterProfessionFactory.php index 524a618..b8248fb 100644 --- a/database/factories/CharacterProfessionFactory.php +++ b/database/factories/CharacterProfessionFactory.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Character; use App\Models\Profession; +use App\Models\Spell; class CharacterProfessionFactory extends Factory { @@ -43,6 +44,7 @@ class CharacterProfessionFactory extends Factory $id = self::$ids[$ch_id][] = Profession::whereNotIn('id', self::$ids[$ch_id])->get()->random()->id; return $id; }, + 'specialization_id' => Spell::factory(), 'skill' => $this->faker->numberBetween(1, 375), ]; }