I have used a seeder to fill up data on my database! However, it doesn’t show up on my blade file! and it just only the table. I tried various methods, including changing the route file and to add data directly from Phpmyadmin.
Blade
<table>
<tr>
<td>Id</td>
<td>bedrijven_id</td>
<td>Body</td>
<td>Created at</td>
<td>Updated at</td>
<td><button type="button">Soliciteer</button></td>
</tr>
@if(isset($data))
@foreach($vacatures as $vacature)
<tr>
<td>{{$vacature['id']}}</td>
<td>{{$vacature['bedrijven_id']}}</td>
<td>{{$vacature['body']}}</td>
<td>{{$vacature['created_at']}}</td>
<td>{{$vacature['updated_at']}}</td>
</tr>
@endforeach
Controller
class Vacatures extends Controller
{
function viewLoad()
{
return view('vacatures');
}
function show() {
$data = Vacature::all();
return view('list', ['vacatures' => $data]);
}
}
Route
Route::get('list',[Vacatures::class,'show']);
3
Answers
The
$data
variable only exists within your controller, it is not passed through to the view.Change this:
To this:
As of comments from @ths and @Omar, the
$data
is not passed to view.By additional,
$vacatures
is instance of Eloquent collection at all.So for readable, you can check$vacatures->isNotEmpty()
instead ofisset
New laravel version also supports blade
@forelse
(documentation)Instead of
isset($data)
useisset($vacatures)
, because you passedvacatures
to view file notdata