Exemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update(Ad $ad, AdRequest $request)
 {
     $this->restoreIfTrashed($ad);
     $oldStatus = $ad->adstatus->title;
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $user = User::findOrFail($request->get('user_id'));
     $category = Category::findOrFail($request->get('category_id'));
     $ad->user()->associate($user);
     $ad->category()->associate($category);
     $ad->geolocation->fill($geo->get());
     $ad->content->fill($request->get('content'));
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeUpdated($ad, $this->admin));
     $ad->save();
     $ad->geolocation->save();
     $ad->content->save();
     if ($ad->adtype->can_update_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_update_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     if ($oldStatus != 'pending') {
         event(new AdWasUpdated($ad, $this->admin));
     }
     return redirect()->route('zxadmin.ad.edit', $ad->id);
 }