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

Nicho's avatar
Level 1

Laravel : @include

Hello, this is my first time using @include in laravel. When i'm trying to using it, i got this error message : Undefined variable: bookOther (View: /home/infinitr/pinus.infinitree.eco/modules/Tour/Views/frontend/guest_list.blade.php)

How can i fix this?? The Controller :

public function guests_list($id){
            $booking = Booking::where('id', $id)->first();
            $bookOther = BookOther::where('booking_id', '=', $booking->id)->get();
            
            return view('Tour::frontend.guest_list', ['booking'=>$booking, 'bookOther'=>$bookOther, 'layout'=>'guest_list']);
            
        }

The Route :

Route::get('/guest_list/{id}', '\Modules\Tour\Controllers\TourController@guests_list')->name('guest_list');

The detail-modal blade :

<div class="tab-pane fade"><br>
                        @include ('Tour::frontend/guest_list')
                    </div>

The guest_list blade :

<h2 class="title-bar no-border-bottom">
        {{__("Booking History")}}
    </h2>
    <div class="card-body">
                    <table class="table">
                        <thead>
                          <tr>
                            <th scope="col">Booking ID : {{$booking->id}}</th>
                          </tr>
                        </thead>
                        <tbody>
                            @foreach ($bookOther as $book)
                              <tr>
                                  <td>{{$book->id}}</td>
                                  <td>{{$book->booking_id}}</td>
                                  <td>{{$book->user_id}}</td>
                                  <td>{{$book->other_emails}}</td>
                              </tr>
                            @endforeach
                        </tbody>
                      </table>
                </div>
0 likes
6 replies
Nicho's avatar
Level 1

@AungHtetPaing__ Like a path to the blade file. I tried to replace the / with . and still got the same error. But other blade file using @include is working fine like this one :

The detail blade :

@include('Tour::frontend.layouts.details.tour-detail')
AungHtetPaing__'s avatar

@Nicho based on my understanding include is subview so it doesn't work with controller directly and it accept data from parent view.

// normally all variables from parent view are available in subview
@include('view.name', ['bookOther' => $bookOther])

Please or to participate in this conversation.