【问题标题】:Laravel views: syntax error, unexpected 'endif' (T_ENDIF)Laravel 视图:语法错误,意外的 'endif' (T_ENDIF)
【发布时间】:2018-04-03 02:45:32
【问题描述】:

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

  • 身份证
  • 姓氏
  • 名字
  • 电话

但他告诉我这个错误:

6361dda302a0f162671ee5b36a4abe93 第 26 行中的 FatalErrorException: 语法错误,意外的 '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 

创建控制器:

<?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]);
    }

【问题讨论】:

    标签: php laravel view laravel-blade


    【解决方案1】:

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

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

    Laravel 希望你先关闭 @foreach,这就是它抛出异常的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-16
      • 2018-11-06
      • 2017-10-30
      • 2013-12-07
      • 2014-10-15
      • 2014-06-15
      • 2014-10-16
      • 2021-09-04
      相关资源
      最近更新 更多