Answer the question
In order to leave comments, you need to log in
Why is an exception thrown when using @foreach?
Good day)
Essence: We have several models:
# Recipe
class Recipe extends Model
{
public function tags()
{
return $this->belongsToMany('App\Models\Tag');
}
public function ingredients()
{
return $this->belongsToMany('App\Models\Ingredient')->withPivot('amount');
}
public function getRouteKeyName()
{
return 'slug';
}
}
# Tags
class Tag extends Model
{
protected $fillable = [
'name', 'slug', 'subsection_id', 'tag_type_id',
];
public function recipes()
{
return $this->belongsToMany('App\Models\Recipe');
}
}
...
public function show(Recipe $recipe)
{
return view('pages/recipes/show', compact('recipe'));
}
@foreach($recipe->ingredients as $ingredients)
@foreach($recipe->tags as $item)
dd($recipe->tags)
{{ var_dump($recipe->tags) }}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question