Home > Mobile >  Blade won't show data from PHPMyAdmin
Blade won't show data from PHPMyAdmin

Time:04-06

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'\]);

CodePudding user response:

The $data variable only exists within your controller, it is not passed through to the view.

Change this:

isset($data)

To this:

isset($vacatures)

CodePudding user response:

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 of isset

New laravel version also supports blade @forelse (documentation)

  • Related