Archived
1
0
Fork 0
This repository has been archived on 2026-06-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
heritage-wow/app/Models/CharacterProfession.php
2021-06-28 17:33:29 +01:00

88 lines
1.7 KiB
PHP

<?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;
}
}