代码之家  ›  专栏  ›  技术社区  ›  Martin antonsson

Laravel视图:语法错误,意外的“endif”(T\u endif)

  •  2
  • Martin antonsson  · 技术社区  · 7 年前

    我有一个视图,我想显示数据库中的记录

    • 身份证件
    • 姓氏
    • 名字

    但他告诉我这个错误:

    6361dda302a0f162671ee5b36a4abe93第26行中的FatalErrorException:

    欢迎刀身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 App\Http\Controllers;
    
    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]);
        }
    
    1 回复  |  直到 7 年前
        1
  •  8
  •   Alexey Mezenin    7 年前

    你需要使用 @endforeach 而不是 @enforeach

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

    @foreach