skip to Main Content

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


  1. If you’re passing data to the controller using with(), you need to bind it with an accessor.

    ->with('consultation', $consultation)
    
    return view('dashboard/admin_panel/p_consultation')->with('consultation', $consultation);
    

    You can use compact() as well


    Example.

    return view('greeting')
                ->with('name', 'Victoria')
                ->with('occupation', 'Astronaut');
    
    Login or Signup to reply.
  2. change from

    return view ('dashboard/admin_panel/p_consultation')->with( $consultation);
    

    to

    return view ('dashboard/admin_panel/p_consultation', ['consultation' => $consultation]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search