initial commit
This commit is contained in:
commit
1e1aa7d461
215 changed files with 35140 additions and 0 deletions
47
app/Models/Item.php
Normal file
47
app/Models/Item.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in a new issue