Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deepu07's avatar
Level 11

Empty output in blade view

Hi, somehow my foreach loop code is showing an empty output in the blade view. jus wondering am I doing anything wrong here? Thanks in advance.

@section('content')
    <div class="row">
        <table class="table table-hover">
            <caption>List of Students</caption>
            <thead>
            <tr>
                <th scope="col">Id</th>
                <th scope="col">name</th>
                <th scope="col">number</th>
            </tr>
            </thead>
            <tbody>
            @foreach($students as $student)
            <tr>
                <th scope="row">1</th>
                <td>{{ $student['id'] }}</td>
                <td>{{ $student['name'] }}</td>
                <td>{{ $student['number'] }}</td>
            </tr>
            @endforeach
            </tbody>
        </table>
    </div>
@endsection
0 likes
10 replies
Sinnbeck's avatar

How do you get students in your controller?

ismaile's avatar

I cannot see anything wrong with your code. $students appears to be empty. It might be interesting to have a look at your eloquent or DB query.

Snapey's avatar

You need to please show some code

deepu07's avatar
Level 11

@sinnbeck @ismaile I'm getting students from the controller if I do {!! dd($students) !!} I'm able to see the list of students (array)

ismaile's avatar

Ok and how are you returning the information ? If possible, that would help if we could see the controller code

deepu07's avatar
Level 11

@snapey here is my controller logic.

$students = DB::table('students')
            ->select('*')
            ->where('type', '=', 'new')
            ->get()
            ->toArray();

return view('students.list', $students);
Sinnbeck's avatar

Try this

return view('students.list', ['students' => $students] );
1 like
clubcouleurs's avatar

Try this :

return view('students.list', compact('students'));

1 like

Please or to participate in this conversation.