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/Item.php
2021-06-28 17:33:29 +01:00

47 lines
866 B
PHP

<?php
namespace App\Models;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
use HasFactory;
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'external_id',
'texture',
'color'
];
protected static function boot() {
parent::boot();
static::creating(function ($item) {
$item->slug = Str::slug($item->name);
});
}
public function recipe()
{
return $this->belongsTo(Recipe::class, 'id');
}
public function getQuantityAttribute()
{
if ($this->pivot) {
return $this->pivot->quantity;
}
return null;
}
}