public function handle(LoanWasCreated $event) { $cons = Condition::where('loantype_id', $event->loan->loan_type_id)->get(); $globs = Globvar::all(); $g = $globs[0]; foreach ($cons as $con) { Loancondition::create(['loan_id' => $event->loan->id, 'crop_year' => $g->crop_year, 'category' => 'loan', 'condition' => $con->condition]); } }
public function remove_award($offer_id) { $offer = Offer::findOrFail($offer_id); if (Gate::denies('remove-award', $offer)) { abort(403); } // Update Offer status $offer->status = 0; $offer->save(); // Update Violation status $violation = $offer->violation; $violation->status = 0; $violation->save(); // Delete all conditions asociated with this offer Condition::where('offer_id', $offer_id)->delete(); // Send email $email = $offer->author->email; $to = $offer->author->username; $customer_name = $offer->violation->author->username; $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; $offer_id = $offer->id; $data = compact('to', 'customer_name', 'address', 'offer_id'); Mail::send('emails.revokeofferaward', $data, function ($message) use($email) { $message->subject('Your offer is no longer awarded!'); $message->to($email); }); // Flash message Session::flash('message', 'You have revoked the award to this offer.'); Session::flash('message-type', 'success'); // Redirect return redirect()->action('OfferController@show', [$offer_id]); }