@tippin - you are extremely helpful. Spent the entire day working this out - not saying it's the best way but it works.
After getting too many emails/second type error on the first loops I watched the entire queue series at laracasts and got that issue solved..
Here's a sample email it spit out!!!
Your job has bidded: Phone number test
The low bid was 25,782.01 //dollars
The following bids were placed:
- 27,173.22 //dollars
- 25,782.01 //dollars
- 30,374.64 //dollars
- 89,640.66 //dollars
Pay for your order now //button
Thank you,
BidBird
Back to the original post and the handle()—is this too much logic to have here or is this kind of what you envisioned??
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$biddedJobs = SlugJob::where([
['deadline', '<=', Carbon::now('America/Los_Angeles')->toDateTimeString()],
['bidded', '=', 0]
])
->get();
foreach ($biddedJobs as $biddedJob):
$bids = $biddedJob->bids;
$sortedHighBids = $bids->sortByDesc('bid');
$sortedHighBids->pop();
// dd($sortedHighBids);
foreach ($sortedHighBids as $sortedHighBid):
$highBidUser = $sortedHighBid->user;
// dd($sortedHighBid);
$highBidUser->notify(new SendJobBiddedLosingBiddersNotified($sortedHighBid));
// dd('hi');
endforeach;
endforeach;
foreach ($biddedJobs as $biddedJob):
$bids = $biddedJob->bids;
$lowBid = $bids->sortBy('bid');
$lowBid->splice(1);
// dd($lowBid);
// dd($lowBid->first()->user);
$winningBidder = $lowBid->first()->user;
// dd($winningBidder);
$winningBidder->notify(new SendJobBiddedWinningBidderNotified($biddedJob));
endforeach;
foreach ($biddedJobs as $biddedJob):
// dd($biddedJob);
$buyer = $biddedJob->first()->user;
$buyer->notify(new SendJobBiddedBuyerNotified($biddedJob));
endforeach;
DB::transaction(function () {
DB::table('jobs')->where([
['deadline', '<=', Carbon::now('America/Los_Angeles')->toDateTimeString()],
['bidded', '=', 0]
])
->update(['bidded' => 1]);
});
}