php - Laravel - 意外的 ':' 期待 '('

标签 php mysql laravel

今天我正在尝试检查计数以确保在未找到任何内容时我可以显示友好的消息,但我一直从 Laravel 收到此错误?

Parse error: syntax error, unexpected ':', expecting '(' (View: C:\Users\User\workspace\websites\website\resources\views\frontend\community\government.blade.php)

当我添加时发生:

 @if ($governmentRole->stats->count() < 1)

一旦我删除了 if 语句,它就可以正常工作。

这是 government.blade.php 中的 foreach:

<div class="panel panel-info">
    <div class="panel panel-body">
        @if ($juniorGovernment->count() < 1)
            We couldn't find any government roles for this category.
        @else
            @foreach($juniorGovernment as $governmentRole)
                @if ($governmentRole->stats->count() < 1)
                    There are currently no candigates working in this category.
                @elseif
                    @foreach($governmentRole->stats as $governmentMember)
                        <div class="col-md-10">
                            <div class="col-md-12" style="margin-left:-40px;">
                                <div class="col-md-1" style="margin-top:-16px;"><img src="http://mywebsite.com/avatar.php?figure=ch-3030-92.hr-681-34.hd-209-8.lg-3116-106-1408&size=b&direction=3&head_direction=3"></div>
                                <div class="col-md-9" style="margin-left:40px;">
                                    <h4>{{ $governmentMember->user->username }} <small>{{ $governmentRole->government_title }}</small></h4>
                                    <p><font color="#aaa">{{ $governmentRole->government_department }}</font></p><br>
                                </div>
                            </div>
                        </div>
                    @endforeach
                @endif
            @endforeach
        @endif
    </div>
</div>

Government.blade.php Controller :

<?php

namespace App\Http\Controllers\Frontend\User;

use Auth;
use Cache;
use Illuminate\Http\Request;
use App\Database\Website\User\Roleplay;
use App\Database\Website\Roleplay\GovernmentRole;
use App\Database\Website\Roleplay\Life\LifeEvents;

class GovernmentController
{
    public function getView()
    {
        $royalty = GovernmentRole::where('government_type', 'royalty');

        $higherGovernment = GovernmentRole::where('government_type', 'higher_government')->get();

        $seniorGovernment = GovernmentRole::where('government_type', 'senior_ministers')->get();

        $juniorGovernment = GovernmentRole::where('government_type', 'junior_ministers')->get();

        return view('frontend.community.government', compact('juniorGovernment', 'seniorGovernment', 'higherGovernment', 'royalty'));
    }
}

最佳答案

@elseif should contain conditional , 但你的是空的。

关于php - Laravel - 意外的 ':' 期待 '(',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41532144/

相关文章:

laravel - 使用 Redis GEOADD 存储 JSON 成员是不好的做法吗?

php - phpmyadmin 使用的路径

mysql - 没有为具有复合键的表创建实体类型

php - Codeigniter插入空值,忽略MySQL中表字段的默认值

java - 在 MySQL 中使用 java.util.Date 对象插入当前日期和时间

javascript - jQuery 脚本只有在函数之上时才有效

php - 如何在 Laravel 5 中删除单条记录?

php - 为 Symfony MicroKernel 注册自定义配置命名空间

php - 如何在 C++ 中加密数据并在 PHP 中解密?

php - 向mysql表中插入数据