jeudi 25 février 2016

Allow a user to bid on a product only once using laravel 5.1

Simple logic required to get this finished, I pray the help of an expert. I'm presently trying a way out to implement a restriction on a bidding website I'm developing, the simplicity is this: a user cannot bid on a product more than once. If the user clicks on the product again, he should be prompted with a response page noting the user of having previously bid on the product,

This is the blade form:

  <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() !!}

This is the controller:

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.');
                }
            }
        }
    }

It's not adding the restriction. It allows user to keep quoting on a product over and over again. Kindly help, please.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire