I want display my data to my blade file but it show this error
Undefined variable $consultation
This is my controller
public function p_consultation()
{
$consultation = Consultation::all();
return view ('dashboard/admin_panel/p_consultation')->with( $consultation);
}
This is my Route
Route::get('dashboard/admin_panel/p_consultation', [PenconsultationController::class, 'Consultation'])
And this is my Blade File
<tr>
<th>#</th>
<th>Item Name</th>
<th>Dscriptiom</th>
<th>Material</th>
<th>Quantity</th>
<th>Start Date</th>
<th>End Date</th>
</tr>
</thead>
<tbody>
@foreach($consultation as $consultation)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $consultation->item_name }}</td>
<td>{{ $consultation->description }}</td>
<td>{{ $consultation->material }}</td>
<td>{{ $consultation->quantity }}</td>
<td>{{ $consultation->start_date }}</td>
<td>{{ $consultation->end_date }}</td>
</tr>
@endforeach
2
Answers
If you’re passing data to the controller using with(), you need to bind it with an accessor.
You can use
compact()
as wellExample.
change from
to