app/Models/Recipe.php: add spell relationship.
This commit is contained in:
parent
78d5d8d50e
commit
86a0474a89
3 changed files with 29 additions and 1 deletions
|
|
@ -32,7 +32,8 @@ class Recipe extends Model
|
|||
protected $fillable = [
|
||||
'profession_id',
|
||||
'category_id',
|
||||
'item_id'
|
||||
'item_id',
|
||||
'spell_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -75,6 +76,14 @@ class Recipe extends Model
|
|||
return $this->belongsTo(RecipeCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* What spell this recipe peforms.
|
||||
*/
|
||||
public function spell()
|
||||
{
|
||||
return $this->belongsTo(Spell::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* What item this recipe crafts.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Database\Factories;
|
|||
|
||||
use App\Models\Profession;
|
||||
use App\Models\Item;
|
||||
use App\Models\Spell;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\RecipeCategory;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ class RecipeFactory extends Factory
|
|||
'profession_id' => Profession::factory(),
|
||||
'category_id' => RecipeCategory::factory(),
|
||||
'item_id' => Item::factory(),
|
||||
'spell_id' => Spell::factory(),
|
||||
//'slug' => function (array $attributes) {
|
||||
// return Str::slug(Item::find($attributes['item_id'])->name);
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Models\RecipeCategory;
|
|||
use App\Models\Profession;
|
||||
use App\Models\CharacterProfession;
|
||||
use App\Models\Character;
|
||||
use App\Models\Spell;
|
||||
use App\Models\Item;
|
||||
|
||||
class RecipeTest extends TestCase
|
||||
|
|
@ -48,6 +49,22 @@ class RecipeTest extends TestCase
|
|||
$this->assertEquals($category->id, $recipe->category->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test spell relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_spell_relationship()
|
||||
{
|
||||
$spell = Spell::factory()->create();
|
||||
|
||||
$recipe = Recipe::factory()
|
||||
->for($spell)
|
||||
->create();
|
||||
|
||||
$this->assertEquals($spell->id, $recipe->spell->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test craft relationship.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue