Here is the error returned by Laravel :
ErrorException compact(): Undefined variable $lists
I am trying to join multiples tables like : Tops has many Lists and Lists has many Medias
I have this code in my TopController :
$tops = Top::with(
'user:id,name,email',
'lists:id',
'categories:title,slug'
)->paginate(20);
I have no problem for retrieve user and categories datas but the lists variable seems to be undefined and I do not understand why.
Here is the Liste.php Model :
public function user()
{
return $this->belongsTo(User::class);
}
public function tops()
{
return $this->belongsToMany(Top::class);
}
public function medias()
{
return $this->belongsToMany(Medias::class);
}
Thank you for your help.
CodePudding user response:
you just need to define a $lists variable in your index method.