How to forbid to accept a offer for car that has already been accepted Laravel Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to Use Order By for Multiple Columns in Laravel 4?Laravel 4: how to “order by” using Eloquent ORMHow to Create Multiple Where Clause Query Using Laravel Eloquent?Checking Resources Reservation AvailabilityLaravel/Ardent - on save(), error: Relationship method must return an object of type IlluminateLaravel Eloquent update just if changes have been madeGet Nested json array of data Laravel Eloquent model with RelationshipHow to connect table User, Offers and Car with relation mysql LaravelGet car with limited offers LaravelHow to connect Car_type, Model and Mark Car Laravel mysql

Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?

How to Make a Beautiful Stacked 3D Plot

8 Prisoners wearing hats

How does the math work when buying airline miles?

Why do we bend a book to keep it straight?

Is safe to use va_start macro with this as parameter?

Do I really need recursive chmod to restrict access to a folder?

How come Sam didn't become Lord of Horn Hill?

Is it common practice to audition new musicians one-on-one before rehearsing with the entire band?

How to react to hostile behavior from a senior developer?

What is the meaning of the simile “quick as silk”?

If a VARCHAR(MAX) column is included in an index, is the entire value always stored in the index page(s)?

Is this homebrew Lady of Pain warlock patron balanced?

For a new assistant professor in CS, how to build/manage a publication pipeline

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How to find all the available tools in mac terminal?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

How to answer "Have you ever been terminated?"

Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?

When the Haste spell ends on a creature, do attackers have advantage against that creature?

Is there such thing as an Availability Group failover trigger?

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

What's the meaning of "fortified infraction restraint"?

How could we fake a moon landing now?



How to forbid to accept a offer for car that has already been accepted Laravel



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to Use Order By for Multiple Columns in Laravel 4?Laravel 4: how to “order by” using Eloquent ORMHow to Create Multiple Where Clause Query Using Laravel Eloquent?Checking Resources Reservation AvailabilityLaravel/Ardent - on save(), error: Relationship method must return an object of type IlluminateLaravel Eloquent update just if changes have been madeGet Nested json array of data Laravel Eloquent model with RelationshipHow to connect table User, Offers and Car with relation mysql LaravelGet car with limited offers LaravelHow to connect Car_type, Model and Mark Car Laravel mysql



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I try the detail to explain the code. The seller receives more offer for his car. When he accepts a certain offer for a particular car, I want to forbid him to accept other offers again for same car.
Example. The seller accepted the offer id. 2, price 3000, car_id 4.
Seller can no longer accept offer id.3 or 4 or 5, price 4000, car_id 4.
Look my code and database



 public function accept($id)
$userId = Auth::user();
$offerId = Offer::with('user')->find($id);
if(!$offerId)
return response()->json([
'message' => 'Oooops this offer does not exist or is currently unavailable'
]);

if($offerId->accepted === 1)
return response()->json([
'message' => 'Oooops this offer is already accepted'
]);


$res = DB::table('offers')
->where('id', $id)
->update(['accepted' => 1]);
if(!$res)
return response()->json([
'message' => 'Ooooops the offer is already accepted'
]);

Mail::to($offerId->user->email)->send(new AcceptOffer());
return response()->json([
'message' => 'Successfully accepted offer',
'offer' => $id
]);




My table Offer with manipulate with offer:



https://imgur.com/ccs4abV



Relation between Offer and Car and User:



Car:



public function user() 
return $this->belongsTo('AppUser');

public function offer()
return $this->hasMany('AppOffer');



Offer:



public function car() 
return $this->belongsTo('AppCar');

public function user()
return $this->belongsTo('AppUser');



User:



public function cars()
return $this->hasMany('AppCar');

public function offers()
return $this->hasMany('AppOffer');










share|improve this question




























    0















    I try the detail to explain the code. The seller receives more offer for his car. When he accepts a certain offer for a particular car, I want to forbid him to accept other offers again for same car.
    Example. The seller accepted the offer id. 2, price 3000, car_id 4.
    Seller can no longer accept offer id.3 or 4 or 5, price 4000, car_id 4.
    Look my code and database



     public function accept($id)
    $userId = Auth::user();
    $offerId = Offer::with('user')->find($id);
    if(!$offerId)
    return response()->json([
    'message' => 'Oooops this offer does not exist or is currently unavailable'
    ]);

    if($offerId->accepted === 1)
    return response()->json([
    'message' => 'Oooops this offer is already accepted'
    ]);


    $res = DB::table('offers')
    ->where('id', $id)
    ->update(['accepted' => 1]);
    if(!$res)
    return response()->json([
    'message' => 'Ooooops the offer is already accepted'
    ]);

    Mail::to($offerId->user->email)->send(new AcceptOffer());
    return response()->json([
    'message' => 'Successfully accepted offer',
    'offer' => $id
    ]);




    My table Offer with manipulate with offer:



    https://imgur.com/ccs4abV



    Relation between Offer and Car and User:



    Car:



    public function user() 
    return $this->belongsTo('AppUser');

    public function offer()
    return $this->hasMany('AppOffer');



    Offer:



    public function car() 
    return $this->belongsTo('AppCar');

    public function user()
    return $this->belongsTo('AppUser');



    User:



    public function cars()
    return $this->hasMany('AppCar');

    public function offers()
    return $this->hasMany('AppOffer');










    share|improve this question
























      0












      0








      0








      I try the detail to explain the code. The seller receives more offer for his car. When he accepts a certain offer for a particular car, I want to forbid him to accept other offers again for same car.
      Example. The seller accepted the offer id. 2, price 3000, car_id 4.
      Seller can no longer accept offer id.3 or 4 or 5, price 4000, car_id 4.
      Look my code and database



       public function accept($id)
      $userId = Auth::user();
      $offerId = Offer::with('user')->find($id);
      if(!$offerId)
      return response()->json([
      'message' => 'Oooops this offer does not exist or is currently unavailable'
      ]);

      if($offerId->accepted === 1)
      return response()->json([
      'message' => 'Oooops this offer is already accepted'
      ]);


      $res = DB::table('offers')
      ->where('id', $id)
      ->update(['accepted' => 1]);
      if(!$res)
      return response()->json([
      'message' => 'Ooooops the offer is already accepted'
      ]);

      Mail::to($offerId->user->email)->send(new AcceptOffer());
      return response()->json([
      'message' => 'Successfully accepted offer',
      'offer' => $id
      ]);




      My table Offer with manipulate with offer:



      https://imgur.com/ccs4abV



      Relation between Offer and Car and User:



      Car:



      public function user() 
      return $this->belongsTo('AppUser');

      public function offer()
      return $this->hasMany('AppOffer');



      Offer:



      public function car() 
      return $this->belongsTo('AppCar');

      public function user()
      return $this->belongsTo('AppUser');



      User:



      public function cars()
      return $this->hasMany('AppCar');

      public function offers()
      return $this->hasMany('AppOffer');










      share|improve this question














      I try the detail to explain the code. The seller receives more offer for his car. When he accepts a certain offer for a particular car, I want to forbid him to accept other offers again for same car.
      Example. The seller accepted the offer id. 2, price 3000, car_id 4.
      Seller can no longer accept offer id.3 or 4 or 5, price 4000, car_id 4.
      Look my code and database



       public function accept($id)
      $userId = Auth::user();
      $offerId = Offer::with('user')->find($id);
      if(!$offerId)
      return response()->json([
      'message' => 'Oooops this offer does not exist or is currently unavailable'
      ]);

      if($offerId->accepted === 1)
      return response()->json([
      'message' => 'Oooops this offer is already accepted'
      ]);


      $res = DB::table('offers')
      ->where('id', $id)
      ->update(['accepted' => 1]);
      if(!$res)
      return response()->json([
      'message' => 'Ooooops the offer is already accepted'
      ]);

      Mail::to($offerId->user->email)->send(new AcceptOffer());
      return response()->json([
      'message' => 'Successfully accepted offer',
      'offer' => $id
      ]);




      My table Offer with manipulate with offer:



      https://imgur.com/ccs4abV



      Relation between Offer and Car and User:



      Car:



      public function user() 
      return $this->belongsTo('AppUser');

      public function offer()
      return $this->hasMany('AppOffer');



      Offer:



      public function car() 
      return $this->belongsTo('AppCar');

      public function user()
      return $this->belongsTo('AppUser');



      User:



      public function cars()
      return $this->hasMany('AppCar');

      public function offers()
      return $this->hasMany('AppOffer');







      mysql laravel eloquent






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 9:35









      Alex AlAlex Al

      507




      507






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Just simple check, if there is some offer for that specific car allready accepted.



          $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->count(); 
          if($acceptedCount > 0)
          return response()->json([
          'message' => 'Another offer for this car was already accepted'
          ]);






          share|improve this answer























          • This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

            – Alex Al
            Mar 22 at 10:19











          • Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

            – Autista_z
            Mar 22 at 10:22







          • 1





            Perfect. Nice man. You have vote.

            – Alex Al
            Mar 22 at 10:31











          • Only one think. Can you explain me what happened in this code? count() what ? :)

            – Alex Al
            Mar 22 at 10:35






          • 1





            You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

            – Autista_z
            Mar 22 at 11:28












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296654%2fhow-to-forbid-to-accept-a-offer-for-car-that-has-already-been-accepted-laravel%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Just simple check, if there is some offer for that specific car allready accepted.



          $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->count(); 
          if($acceptedCount > 0)
          return response()->json([
          'message' => 'Another offer for this car was already accepted'
          ]);






          share|improve this answer























          • This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

            – Alex Al
            Mar 22 at 10:19











          • Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

            – Autista_z
            Mar 22 at 10:22







          • 1





            Perfect. Nice man. You have vote.

            – Alex Al
            Mar 22 at 10:31











          • Only one think. Can you explain me what happened in this code? count() what ? :)

            – Alex Al
            Mar 22 at 10:35






          • 1





            You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

            – Autista_z
            Mar 22 at 11:28
















          1














          Just simple check, if there is some offer for that specific car allready accepted.



          $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->count(); 
          if($acceptedCount > 0)
          return response()->json([
          'message' => 'Another offer for this car was already accepted'
          ]);






          share|improve this answer























          • This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

            – Alex Al
            Mar 22 at 10:19











          • Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

            – Autista_z
            Mar 22 at 10:22







          • 1





            Perfect. Nice man. You have vote.

            – Alex Al
            Mar 22 at 10:31











          • Only one think. Can you explain me what happened in this code? count() what ? :)

            – Alex Al
            Mar 22 at 10:35






          • 1





            You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

            – Autista_z
            Mar 22 at 11:28














          1












          1








          1







          Just simple check, if there is some offer for that specific car allready accepted.



          $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->count(); 
          if($acceptedCount > 0)
          return response()->json([
          'message' => 'Another offer for this car was already accepted'
          ]);






          share|improve this answer













          Just simple check, if there is some offer for that specific car allready accepted.



          $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->count(); 
          if($acceptedCount > 0)
          return response()->json([
          'message' => 'Another offer for this car was already accepted'
          ]);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 9:52









          Autista_zAutista_z

          1,694518




          1,694518












          • This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

            – Alex Al
            Mar 22 at 10:19











          • Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

            – Autista_z
            Mar 22 at 10:22







          • 1





            Perfect. Nice man. You have vote.

            – Alex Al
            Mar 22 at 10:31











          • Only one think. Can you explain me what happened in this code? count() what ? :)

            – Alex Al
            Mar 22 at 10:35






          • 1





            You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

            – Autista_z
            Mar 22 at 11:28


















          • This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

            – Alex Al
            Mar 22 at 10:19











          • Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

            – Autista_z
            Mar 22 at 10:22







          • 1





            Perfect. Nice man. You have vote.

            – Alex Al
            Mar 22 at 10:31











          • Only one think. Can you explain me what happened in this code? count() what ? :)

            – Alex Al
            Mar 22 at 10:35






          • 1





            You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

            – Autista_z
            Mar 22 at 11:28

















          This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

          – Alex Al
          Mar 22 at 10:19





          This is work fine but this function is run over my message 'message' => 'Oooops this offer is already accepted' how to return that? If user click on same offer got message above, but if click on another offer of same car got message 'Another offer for this car was already accepted'

          – Alex Al
          Mar 22 at 10:19













          Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

          – Autista_z
          Mar 22 at 10:22






          Well then just exclude current offer: $acceptedCount = Offer::where('car_id', $offerId->car_id)->where('accepted', 1)->where('id', '!=', $offerId->id)->count();

          – Autista_z
          Mar 22 at 10:22





          1




          1





          Perfect. Nice man. You have vote.

          – Alex Al
          Mar 22 at 10:31





          Perfect. Nice man. You have vote.

          – Alex Al
          Mar 22 at 10:31













          Only one think. Can you explain me what happened in this code? count() what ? :)

          – Alex Al
          Mar 22 at 10:35





          Only one think. Can you explain me what happened in this code? count() what ? :)

          – Alex Al
          Mar 22 at 10:35




          1




          1





          You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

          – Autista_z
          Mar 22 at 11:28






          You count number of Offers, which have same car_id (same value in database in column car_id) as $offerId (current offer, which you want to accept) and also are accepted (column accepted is set to 1). But you exclude current offer (by its ID).

          – Autista_z
          Mar 22 at 11:28




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296654%2fhow-to-forbid-to-accept-a-offer-for-car-that-has-already-been-accepted-laravel%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript