I have a problem, blade not find the variable: editor. This is the function of my Controller.
public function HomeText()
{
$data = [];
$data['editor'] = Editore::get();
return view('home')->with($data);
}
And these are the instructions in the file blade.php:
<select class="form-control select_editore">
@foreach ($editor as $editore)
<option>
{{ $editore->id_editore, $editore->nome_editore }}
</option>
@endforeach
</select>
What is the error? I hope that you help me! I'm newbie with Laravel, I want to understand where I'm wrong.
Change it to this if you want to use an array:
return view('home', $data);
If you want to use ->with()
, do this:
->with('editor', $data['editor'])
Change this:
public function HomeText()
{
$data = [];
$data['editor'] = Editore::get();
return view('home')->with($data);
}
to this:
public function HomeText()
{
$editor = Editore::all();
return view('home',compact('editor'));
}
and in your blade file change <option>{{ $editore->id_editore, $editore->nome_editore }}</option>
to <option>{{ $editore->id_editore}}, {{$editore->nome_editore }}</option>
In your way of coding you can’t call $editor
directly.
You have to use, $data[‘editor’] as $editore
<select class="form-control select_editore">
@foreach ($data[‘editor’] as $editore)
<option>
{{ $editore->id_editore, $editore->nome_editore }}
</option>
@endforeach
you may want to change the way you pass the variable to this
public function HomeText()
{
$data = [];
$data['editor'] = Editore::get(); // or all()
return view('home', $data);
}
then you may now use $editor
in your blade ..