protected function createAd($adtype, $data) { $geo = new Geolocation($data['geolocation_data']); $adstatus = Adstatus::whereTitle('pending')->first(); $ad = new Ad(); $ad->user_id = $data['user_id']; $ad->category_id = $data['category_id']; $ad->adstatus()->associate($adstatus); $ad->adtype()->associate($adtype); $ad->save(); $ad->geolocation()->create($geo->get()); $ad->content()->create($data['content']); if ($ad->adtype->can_add_pic) { $this->syncAdPhotos($ad, $data); } if ($ad->adtype->can_add_video) { $this->syncAdVideos($ad, $data); } $this->syncAdFields($ad, $data); event(new AdWasCreated($ad, 'ZEDx')); $this->validateAd($ad); }
/** * 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); }
/** * Update the specified resource in storage. * * @param int $id * * @return Response */ public function update(Ad $ad, UpdateAdUserRequest $request) { if (!$ad->adtype->can_edit) { return ['adId' => null]; } $oldStatus = $ad->adstatus->title; $geo = new GeolocationHelper($request->get('geolocation_data')); $adstatus = Adstatus::whereTitle('pending')->first(); $category = Category::visible()->findOrFail($request->get('category_id')); $ad->category()->associate($category); $ad->adstatus()->associate($adstatus); $ad->geolocation->fill($geo->get()); $ad->content->fill($request->get('content')); $ad->price = $this->getPrice($ad, $request); event(new AdWillBeUpdated($ad, $this->user)); $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->user)); } return ['adId' => $ad->id]; }