Reputation: 1635
today I am trying to check the count to ensure I can display a friendly message if nothing is found, but I keep getting this error from Laravel?
Parse error: syntax error, unexpected ':', expecting '(' (View: C:\Users\User\workspace\websites\website\resources\views\frontend\community\government.blade.php)
Happens when I add:
@if ($governmentRole->stats->count() < 1)
Once I remove that if statement it works fine.
Here is the foreach in government.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 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'));
}
}
Upvotes: 1
Views: 83
Reputation: 21691
I think your code need to update if statement
part like:
@if ($governmentRole->stats->count() < 1)
To
@if(count($governmentRole->stats) < 1)
Hope this work for you!
Upvotes: 0