34 lines
633 B
PHP
34 lines
633 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Product extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'products';
|
|
|
|
protected $fillable = [
|
|
'sort_order',
|
|
'category',
|
|
'products',
|
|
'description'
|
|
];
|
|
|
|
protected $casts = [
|
|
'products' => 'array',
|
|
];
|
|
|
|
public function ingredients()
|
|
{
|
|
return Ingredient::whereIn('id', collect($this->products ?? [])
|
|
->pluck('ingredients')
|
|
->flatten()
|
|
->unique()
|
|
->toArray()
|
|
);
|
|
}
|
|
} |