如何比较/检查是否返回了用户的先前状态。如果返回,则该用户可以借书。如果不是,或者当前的状态是当前借用的,则他不能借书。
代码似乎不正确。如果用户借书,则修复状态将始终为“待处理”。
这里是我做的,但是不起作用。
if ($borrow->status === 'Returned') {
$borrow = new BorrowBook();
$borrow->book_name = $borrow->book_name;
$borrow->date_borrowed = $borrow->date_borrowed('date_borrowed');
$borrow->status = 'Pending';
} elseif (BorrowBook::where('status', $borrow->status === 'Currently Borrowed')->exist()) {
return redirect('/borrow')->with('success', 'Your previous book has not been returned yet');
}
答案 0 :(得分:0)
您的elseif
总是返回true,请尝试使用它,
elseif(count(BorrowBook::where('status',$borrow->status == "Currently Borrowed")->get())) {
return redirect('/borrow')->with('success','Your previous book has not been returned yet');
}