Laravel views: syntax error, unexpected 'endif' (T
I have a views and i would like to display the records that is in the database
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')
<div class="container">
<div class="row">
<legend>List</legend>
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>ID</th>
<th>lastaname</th>
<th>firstname</th>
<th>phone</th>
</tr>
</thead>
<tbody>
@if (count($customers) > 0 )
@foreach($customers->all() as $customer)
<tr>
<td>{{ $customer->id }}</td>
<td>{{ $customer->lastaname }}</td>
<td>{{ $customer->firstname }}</td>
<td>{{ $customer->phone }}</td>
</tr>
@enforeach
@endif
</tbody>
</table>
</div>
</div>
@endsection
CreatesController :
<?php namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use IlluminateHttpRequest;
use AppCustomer;
class CreatesController extends Controller {
public function welcome()
{
$customers = Customer::all();
return view('welcome', ['customers' => $customers]);
}
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.
上一篇: 把一个PHP变量作为文本框的值