我如何检查是否有可变的laravel? [英] how can i check there is an variable laravel?
本文介绍了我如何检查是否有可变的laravel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为我试图通过 $ reservations
时,数据库中有一些保留,没有错误,但是当它为空时,我得到了错误
i have this on my view im trying to pass $reservations
when there is some reservations in DB there is no error but when it is empty i got error
未定义变量:保留(查看:C:\ Users \ yass \ Desktop \ E-tourisme-44 \ E-tourisme-5554 \ resources \ views \ moderateur \ reservation.blade.php)
Undefined variable: reservations (View: C:\Users\yass\Desktop\E-tourisme-44\E-tourisme-5554\resources\views\moderateur\reservation.blade.php)
模板
<tbody>
@if($reservations )
@foreach($reservations as $reservation)
<tr>
<td> {{$reservation->children}} </td>
<td> {{$reservation->checkin}} </td>
<td> {{$reservation->checkout}} </td>
<td>
@endforeach
@else
<div>
No Data
</div>
@endif
</tbody>
这是我的功能
public function index()
{
$myhotels = hotel::where('created_by', Auth::user()->id)->first();
if ($myhotels) {
$reservations = Reservation::where('hotel_id', $myhotels->id)->get();
return view('moderateur/reservation', compact('reservations'));
}
return view('moderateur/reservation');
}
推荐答案
尝试使用:
@if(isset($reservations))
这篇关于我如何检查是否有可变的laravel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文