public function store($offer_id, Request $request)
 {
     $offer = Offer::findOrFail($offer_id);
     if (Gate::denies('close-offer', $offer)) {
         abort(403);
     }
     $rate = new Rate();
     $rate->fill($request->input());
     $rate->pro_id = Auth::user()->id;
     $rate->offer_id = $offer_id;
     $rate->save();
     $offer->status = 6;
     $offer->save();
     // Send email
     $violation = $offer->violation;
     $violation->status = 6;
     $violation->save();
     $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.offerclosed', $data, function ($message) use($email) {
         $message->subject('You have been reviewed!');
         $message->to($email);
     });
     // Flash message
     Session::flash('message', 'You have submitted a review and closed this offer.');
     Session::flash('message-type', 'success');
     // Redirect
     return redirect()->action('OfferController@show', [$offer_id]);
 }
 public function store(Requests\SaveCommentRequest $request, $offer_id)
 {
     $offer = Offer::findOrFail($offer_id);
     if (Gate::denies('add-comment', $offer)) {
         abort(403);
     }
     $comment = new Comment();
     $comment->fill($request->input());
     $comment->user_id = Auth::user()->id;
     $comment->offer_id = $offer_id;
     $comment->save();
     $violation = $offer->violation;
     // Send email
     $user_type = Auth::user()->getOriginal('user_type');
     if ($user_type == 'cus') {
         $to = $offer->author->username;
         $email = $offer->author->email;
     } else {
         $to = $violation->author->username;
         $email = $violation->author->email;
     }
     $poster_name = Auth::user()->username;
     $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip;
     $data = compact('user_type', 'to', 'poster_name', 'address', 'offer_id');
     Mail::send('emails.newcomment', $data, function ($message) use($email) {
         $message->subject('New Comment Posted');
         $message->to($email);
     });
     // Flash message
     Session::flash('message', 'Your comment has been posted to the offer.');
     Session::flash('message-type', 'success');
     // Redirect
     return redirect(url('/offer/' . $offer_id . '#comment_' . $comment->id));
 }
 public function store($offer_id, Requests\SaveConditionRequest $request)
 {
     // Find offer to make sure it exists
     $offer = Offer::findOrFail($offer_id);
     if (Gate::denies('add-condition', $offer)) {
         abort(403);
     }
     // Create new condition and save
     $condition = new Condition();
     $condition->fill($request->input());
     $condition->offer_id = $offer_id;
     $condition->pro_id = Auth::user()->id;
     $condition->save();
     // Flash message
     Session::flash('message', 'You have added a new condition to the offer.');
     Session::flash('message-type', 'success');
     // Redirect
     return redirect(url('/offer/' . $offer_id . '#conditions'));
 }
 public function showOffer($id)
 {
     $offer = Offer::findOrFail($id);
     return view('home.show_offer', compact('offer'));
 }
 public function report_completed($offer_id)
 {
     $offer = Offer::findOrFail($offer_id);
     if (Gate::denies('complete-offer', $offer)) {
         abort(403);
     }
     // Update offer
     $offer->status = 5;
     $offer->save();
     // Update violation
     $violation = $offer->violation;
     $violation->status = 5;
     $violation->save();
     // Send email to the pro
     $email = $offer->violation->author->email;
     $to = $offer->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.offercompleted', $data, function ($message) use($email) {
         $message->subject('Offer Completed!');
         $message->to($email);
     });
     // Flash message
     Session::flash('message', 'You have reported that you have completed solving this violation. The customer <b>' . $violation->author->username . '</b> needs to review before it can be closed.');
     Session::flash('message-type', 'success');
     // Redirect
     return redirect()->action('OfferController@show', [$offer_id]);
 }
Esempio n. 6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     //$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed.
     $offer = Offer::findOrFail($id);
     $update = $request->all();
     // is new image uploaded?
     if ($file = Input::file('image')) {
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = '/uploads/';
         $destinationPath = Config::get('app.path') . $folderName;
         $safeName = time() . "_" . str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         //delete old pic if exists
         if (File::exists(Config::get('app.path') . $offer->image)) {
             File::delete(Config::get('app.path') . $offer->image);
         }
         $update['image'] = $safeName ? $folderName . $safeName : '';
     }
     if (isset(Offer::$boolean)) {
         foreach (Offer::$boolean as $field) {
             if (isset($update[$field]) && $update[$field] == "on") {
                 $update[$field] = 1;
             } else {
                 $update[$field] = 0;
             }
         }
     }
     $offer->update($update);
     return redirect('admin/offers')->with('success', Lang::get('message.success.update'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $offer = Offer::findOrFail($id)->isOwnedOrFail();
     foreach ($offer->pictures as $picture) {
         unlink(storage_path('app/pictures/pic_' . $picture->id));
         $picture->delete();
     }
     $offer->delete();
     flash()->success('Gelöscht.');
     return redirect('host/offers');
 }