我試圖寫一個if-else循環:如果有一個嵌入保存在數據庫中,它應該顯示一個日曆,如果不是,它應該顯示一個按鈕,說「添加新日曆/添加新的嵌入「,但它不起作用。我無法弄清楚爲什麼。當存在保存在數據庫中的嵌入它顯示嵌入但是,如果沒有它不顯示按鈕來添加一個新的日曆/嵌入的嵌入:laravel - if else loop not working proper
刀片視圖:
@if (empty($calendars))
@else
<h4>No calendar settings</h4><br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button">
<i class="fa fa-cloud-upload"></i>
<span class="bold">Add embed</span>
</button>
</a>
@endif
@foreach($calendars as $calendar)
{{ $calendar->embed }}
@endforeach
控制器:
public function kalendarz() {
$calendars = Calendar::with('users')->where('user_id', Auth::user()->id)->get();
return view('kalendarz',['calendars'=>$calendars]);
}
刀片代碼塊告訴「如果沒有日曆什麼都不做」 –