jan
jan

Reputation: 211

two models in blade template in laravel

I have two models, model1 and model2 . I am using this models in blade template and I don't want to use controller for getting value.

 @php
    $school = App\Models\Model1::all()
    $department = App\Models\Model2::all()
@endphp

<select name="school">
     <option value="" selected="">school</option>
         @foreach($school as $val)
         <option value="">{{$val->name}}</option>
          @endforeach
</select>

<select name="departments">
     <option value="" selected="">department</option>
       @foreach($department as $val)
        <option value="">{{$val->name}}</option>
         @endforeach                         
</select>

But I am getting this error:

syntax error, unexpected '$department' (T_VARIABLE) 

But when I call only one model, the data shows perfectly. How can i solve this problem?

Upvotes: 0

Views: 493

Answers (1)

Surya Neupane
Surya Neupane

Reputation: 994

I think you forgot the semicolon.

@php
   $school = App\Models\Model1::all();
   $department = App\Models\Model2::all();
@endphp

Upvotes: 1

Related Questions