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 violation_map($state)
 {
     $states = config('other.states');
     $state_name = $states[strtoupper($state)];
     $violations = Violation::where('state', strtoupper($state))->where('user_id', '>', 0)->get();
     $violations_count = count($violations);
     return view('violation.violation-map', compact('state_name', 'violations', 'violations_count'));
 }
 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());
     }
 }
Example #4
0
 /**
  * Get common page data like Top Violators, Recently Added, List of Violations
  *
  * @return array Data for Top Violators, Recently Added, List of Violations
  */
 public static function getCommonPageData()
 {
     $top_violators = TaxiViolation::getTopViolators(10);
     $taxis = self::getPaginated();
     // This is used by Report Form for list of Violations
     $violations = Violation::lists('name', 'id');
     $data = compact('taxis', 'top_violators', 'violations');
     return $data;
 }