我正在建立一个场地管理系统,并且在目标网页上,我试图向访客显示所有可用的广告位。已预订的客房显示为不可用。我创建了两个变量,一个变量包含时间表中的信息,另一个变量包含预订表中的信息,并尝试使用Blade进行比较和显示。这就是我试图在刀片中实现它的方式:
@foreach($times as $time)
@foreach($bookings as $booking)
<tr>
@if($time->availble_times == $booking->booking_time)
<td>{{$time->availble_times}}: not available</td>
@else
<tr><td>{{$time->availble_times}}</td>
@endif
</tr>
@endforeach
@endforeach
Run Code Online (Sandbox Code Playgroud)
但这反而会一直显示预订表中尽可能多的记录。就像预订表中有两行一样,它显示两次时间,依此类推。以防万一,这是我的控制器功能:
public function times(){
$times = Times::all();
$bookings = Bookings::all();
return view('/test2')->with('times', $times)->with('bookings', $bookings);
}
Run Code Online (Sandbox Code Playgroud)
我最近开始做Laravel,无法弄清楚这个问题。我的问题是,我该如何解决n次显示问题并向用户显示哪些时间被预订以及哪些时间可用?
我试图将一个字符串分解成一个数组,然后在屏幕上打印这些值。这是我试图打破的字符串:
“齿轮|秃鹰”
“|” 使用它来拆分它。这是我的做法:
<?= $arrays = explode('|', $b->brand); foreach($arrays as $array){echo $array;} ?>
Run Code Online (Sandbox Code Playgroud)
但我不断收到此异常:
2/2) ErrorException
Array to string conversion (View: D:\Code\PHP\Code\CrownBillingSystem\resources\views\pages\print.blade.php)
in 6e7ee4930110d4a26a3e31e0ddfe8b87849a1319.php (line 93)
at CompilerEngine->handleViewException(object(ErrorException), 1)
in PhpEngine.php (line 44)
at PhpEngine-
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚这里出了什么问题。