Reputation: 1206
It says undefined variable
when I try to pull variable through compact
this is my controller
public function show()
{
$list = List::find(1)->task();
return view('configuration.configuration', compact($list));
}
this is my view
@foreach($list as $value)
<span> {{ $value->tasks }}</span>
@endforeach
Upvotes: 0
Views: 58
Reputation: 2736
SUGGESTIONS/CORRECTIONS
In $list = List::find(1)->task();
If you are trying to retrieve all task
from list, then I this you are doing it wrong instead you should do something like this:
$list = List::find(1)->task;
Again in return view('configuration.configuration', compact($list));
, if you want to convert to array then compact()
won't do that.
this return view('configuration.configuration', ['list'=>$list->toArray()]);
will do that
An to retrieve or print in view(blade)
, try something like this
@foreach($list as $value=>$val)
<span> {{{ $val['task'] }}}</span> //"task" is just an assumption, replace it with your own ColumnName
@endforeach
if you don't want convert the $list
in array
CONTROLLER
public function show()
{
$list = List::find(1)->task;
return view('configuration.configuration',['list'=> $list]);
}
VIEW
@foreach($list as $value)
<span> {{ $value->tasks }}</span>
@endforeach
Upvotes: 1
Reputation: 300
Maybe change your return view to :
return view('configuration.configuration',['list'=>$list]);
Upvotes: 0