用户对订单的出价不能超过一次。如果用户再次单击该订单,则应该在响应页面上提示他,提示用户先前已经对该订单进行了出价。
OrderController.php
public function store(Request $request)
{
$this->validate(request(), [
'category_id' => 'required'
]);
$order = Order::findOrFail(request('category_id'));
if (auth()->user()->checkOrder($order)) {
alert()->error('Warning', 'You ordered already');
return redirect()->back();
}
}
User.php
public function checkOrder($category)
{
return !! Order::where('user_id' , $this->id)->where('category_id' , $category->id)->first();
}