【发布时间】:2016-06-08 04:25:30
【问题描述】:
完成此操作所需的简单逻辑,我祈求专家的帮助。我目前正在尝试一种方法来对我正在开发的投标网站实施限制,简单的是:用户不能对产品进行多次投标。如果用户再次点击该产品,应该会提示他一个响应页面,指出用户之前曾对该产品出价,
这是刀片形式:
<p><h3>{!! ucfirst($product->productname) !!}</h3></p>
@if(Auth::user()->id === $product->user_id)
<p>Sorry, you posted this product, you cannot quote on it.</p>
@else
<p>{!! Form::label('Higest Price') !!}</p>
<p>{!! Form::number('price', Input::old('price')) !!}</p>
<p>{!! Form::textarea('comments', Input::old('comments')) !!}</p>
<p>{!! Form::hidden('product_id', $product->id) !!}</p>
<p>{!! Form::hidden('company_id', $product->company_id) !!}</p>
<p>{!! Form::hidden('user_id', $product->user_id) !!}</p>
<p>{!! Form::submit('ADD QUOTE') !!}</p>
@endif
{!! Form::close() !!}
这是控制器:
public function store(BiddingCommentRequest $biddingCommentRequest)
{
$biddingComments = new BiddingComments;
$product_id = $biddingCommentRequest->product_id;
$AuthUserBidder = Auth::user()->id;
$bidderCommented = BiddingComments::all();
if($biddingCommentRequest->isMethod('post')){
foreach ($bidderCommented as $key => $commentedBidder) {
if(!count($commentedBidder->id) > 0)
{
$biddingComments->bidder_id = $AuthUserBidder;
$biddingComments->product_id = $product_id;
$biddingComments->company_id = $biddingCommentRequest->company_id;
$biddingComments->user_id = $biddingCommentRequest->user_id;
$biddingComments->comments = $biddingCommentRequest->comments;
$biddingComments->price = $biddingCommentRequest->price;
$biddingComments->save();
return redirect()->route('biddingCommentView', $product_id)->with('message', 'Your question has been posted.');
}elseif(($AuthUserBidder == $commentedBidder->bidder_id) && ($product_id == $commentedBidder->product_id))
{
return redirect()->route('productindex')->with('message', 'Your question has been posted.');
}else
{
$biddingComments->bidder_id = $AuthUserBidder;
$biddingComments->product_id = $product_id;
$biddingComments->company_id = $biddingCommentRequest->company_id;
$biddingComments->user_id = $biddingCommentRequest->user_id;
$biddingComments->comments = $biddingCommentRequest->comments;
$biddingComments->price = $biddingCommentRequest->price;
$biddingComments->save();
return redirect()->route('biddingCommentView', $product_id)->with('message', 'Your question has been posted.');
}
}
}
}
它没有添加限制。它允许用户一遍又一遍地引用产品。请帮忙。
【问题讨论】:
标签: if-statement eloquent laravel-5.1 logical-operators laravel-blade