Wednesday, 4 January 2017

php - Laravel views: syntax error, unexpected 'endif' (T_ENDIF)



I have a views and i would like to display the records that is in the database




  • ID


  • LastName

  • Firstname

  • Phone



But he shows me this error :




FatalErrorException in 6361dda302a0f162671ee5b36a4abe93 line 26:
syntax error, unexpected 'endif' (T_ENDIF)





welcome.blade.php :



@extends('layouts.master')

@section('title')
Welcom!
@endsection


@section('content')



List











@if (count($customers) > 0 )
@foreach($customers->all() as $customer)







@enforeach
@endif

ID lastaname firstname phone
{{ $customer->id }} {{ $customer->lastaname }} {{ $customer->firstname }} {{ $customer->phone }}



@endsection



CreatesController :




use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\Customer;

class CreatesController extends Controller {

public function welcome()
{
$customers = Customer::all();
return view('welcome', ['customers' => $customers]);
}


Answer



You need to use @endforeach instead of @enforeach



https://laravel.com/docs/5.5/blade#loops



Laravel expects you close @foreach first, that's why it throws the exception.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...