Archived
1
0
Fork 0

initial commit

This commit is contained in:
Henrik Hautakoski 2021-06-28 17:33:29 +01:00
commit 1e1aa7d461
215 changed files with 35140 additions and 0 deletions

View file

@ -0,0 +1,88 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class CharacterProfession extends Model
{
use HasFactory;
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'character_id',
'profession_id',
'skill',
];
/**
* The relationships that should always be loaded.
*
* @var array
*/
protected $with = [
'profession'
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [ 'name' ];
/**
* Relation to the actual profession data.
*/
public function profession()
{
return $this->belongsTo(Profession::class);
}
/**
* Get the character that has this profession.
*/
public function character()
{
return $this->belongsTo(Character::class);
}
/**
* Get the character's recipes for this profession.
*/
public function recipes()
{
return $this->belongsToMany(Recipe::class,
'character_profession_recipe', 'ch_prof_id');
}
/**
* Learn a recipe for this character and profession.
*/
public function learn(Recipe $recipe)
{
return $this->recipes()->save($recipe);
}
/**
* Get profession name.
*/
public function getNameAttribute() : string
{
return $this->profession->name;
}
public function getSlugAttribute() : string
{
return $this->profession->slug;
}
}