SC
Size: a a a
SC
VY
АМ
id, weight, grind
id, quantity, temperature
drink_name, description, ingredient_type, ingredient_id
class Drink extends Model {
public function coffees(): \Illuminate\Database\Eloquent\Relations\MorphToMany {
return $this->morphedByMany(Coffee::class, 'ingredient');
}
public function waters(): \Illuminate\Database\Eloquent\Relations\MorphToMany {
return $this->morphedByMany(Water::class, 'ingredient');
}
}
class Coffee extends Model {
public function drinks(): \Illuminate\Database\Eloquent\Relations\MorphToMany {
return $this->morphToMany(Drink::class, 'ingredient');
}
}
class Water extends Model {
public function drinks(): \Illuminate\Database\Eloquent\Relations\MorphToMany {
return $this->morphToMany(Drink::class, 'ingredient');
}
}
public function show(string $recipe){
return Drink::with( 'coffees', 'waters')->findOrFail($recipe);
}
json
{
"name": "espresso",
"coffees": [
{
"id": 1,
"weight": 7,
"grind": "fine",
"pivot": {
"drink_name": "espresso",
"ingredient_id": 1,
"ingredient_type": "App\\Models\\Coffee"
}
}
],
"machines": [],
"milks": [],
"waters": [
{
"id": 1,
"quantity": 30,
"temperature": 90,
"pivot": {
"drink_name": "espresso",
"ingredient_id": 1,
"ingredient_type": "App\\Models\\Water"
}
}
]
}
В
𝚂
AR
$item->product->withTrashed()->first()
не помогает, все равно выбирает deleted_at is null
к
A
$item->product->withTrashed()->first()
не помогает, все равно выбирает deleted_at is null
A
$item->product->withTrashed()->first()
не помогает, все равно выбирает deleted_at is null
AR
public function product()
{
return $this->belongsTo(Product::class, 'product_id')->withTrashed();
}
A
АМ
$item->product->withTrashed()->first()
не помогает, все равно выбирает deleted_at is null
AR
AR
АМ
AR
AR
VY
ВШ
VY