public function store(Requests\SaveOfferRequest $request) { if (Gate::denies('create-offer')) { abort(403); } $violation_id = $request->input('violation_id'); $violation = Violation::findOrFail($violation_id); $offer = new Offer(); $offer->fill($request->input()); $offer->violation_id = $violation_id; $offer->pro_id = Auth::user()->id; $offer->user_id = $violation->author->id; $offer->save(); // Update violation $violation->offers++; $violation->status = 0; $violation->save(); // Send email $email = $violation->author->email; $to = $violation->author->username; $pro_name = $offer->author->username; $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; $offer_id = $offer->id; $data = compact('to', 'pro_name', 'address', 'offer_id'); Mail::send('emails.newoffer', $data, function ($message) use($email) { $message->subject('You have received an offer'); $message->to($email); }); // Flash message $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; Session::flash('message', 'Your offer for violation <b>' . $violation_name . '</b> has been submitted.'); Session::flash('message-type', 'success'); // Redirect return redirect()->action('OfferController@show', [$offer->id]); }
public function postRegisterCustomer(Request $request) { $validator = $this->validator($request->all()); if ($validator->fails()) { $this->throwValidationException($request, $validator); } // Create and log the user in Auth::login($this->create($request->all(), 'cus')); // Send email to the user and admin $to = Auth::user()->username; $user_id = Auth::user()->id; $user_type = 'cus'; $email = Auth::user()->email; $data = compact('to', 'user_id', 'user_type'); // User Mail::send('emails.newuser', $data, function ($message) use($email) { $message->subject('Welcome!'); $message->to($email); }); // Admin Mail::send('emails.newuser-admin', $data, function ($message) { $message->subject('New User'); $message->to(config('other.email')); }); if (session('unregistered-violation')) { session(['unregistered-violation' => false]); $violation = Violation::findOrFail(session('violation_id')); $violation->user_id = Auth::user()->id; $violation->save(); return redirect()->action('ViolationController@show', [$violation->id]); } else { $this->redirectPath = $this->redirectPath . Auth::user()->id; return redirect($this->redirectPath()); } }
public function update(Requests\SaveViolationRequest $request, $id) { if (Gate::denies('create-violation')) { abort(403); } $violation = Violation::findOrFail($id); $violation->fill($request->input()); $violation->save(); // Flash message $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; Session::flash('message', 'Violation <b>' . $violation_name . '</b> has been updated.'); Session::flash('message-type', 'success'); // Redirect return redirect()->action('ViolationController@show', ['id' => $id]); }