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

时间:2017-01-08 11:22:02

标签: 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语句后,一切正常。

这是政府中的foreach.blade.php:

<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控制器:

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

2 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:0)

我认为您的代码需要更新if statement部分,如:

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

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

希望这对你有用!