Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Adtype $adtype, CreateAdUserRequest $request)
 {
     if (($number = $this->numberAdtype($adtype)) <= 0 && $adtype->price > 0) {
         return ['adId' => null];
     }
     if ($this->user->subscription_expired_at) {
         if ($this->user->subscription_expired_at->diffInDays(null, false) >= 0) {
             return ['adId' => null];
         }
     }
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $adstatus = Adstatus::whereTitle('pending')->first();
     $category = Category::visible()->findOrFail($request->get('category_id'));
     $geolocation = new Geolocation();
     $geolocation->fill($geo->get());
     $content = new Adcontent();
     $content->fill($request->get('content'));
     $ad = new Ad();
     $ad->user()->associate($this->user);
     $ad->adtype()->associate($adtype);
     $ad->adstatus()->associate($adstatus);
     $ad->category()->associate($category);
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeCreated($ad, $content, $geolocation, $this->user));
     $ad->save();
     $ad->geolocation()->save($geolocation);
     $ad->content()->save($content);
     if ($ad->adtype->can_add_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_add_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     if ($number < 9999 && $number > 0) {
         $this->user->adtypes->find($adtype->id)->pivot->decrement('number');
     }
     event(new AdWasCreated($ad, $this->user));
     return ['adId' => $ad->id];
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Adtype $adtype, AdRequest $request)
 {
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $adstatus = Adstatus::whereTitle('pending')->first();
     $user = User::findOrFail($request->get('user_id'));
     $category = Category::findOrFail($request->get('category_id'));
     $geolocation = new Geolocation();
     $geolocation->fill($geo->get());
     $content = new Adcontent();
     $content->fill($request->get('content'));
     $ad = new Ad();
     $ad->user()->associate($user);
     $ad->category()->associate($category);
     $ad->adstatus()->associate($adstatus);
     $ad->adtype()->associate($adtype);
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeCreated($ad, $content, $geolocation, $this->admin));
     $ad->save();
     $ad->geolocation()->save($geolocation);
     $ad->content()->save($content);
     if ($ad->adtype->can_add_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_add_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     event(new AdWasCreated($ad, $this->admin));
     return redirect()->route('zxadmin.ad.edit', $ad->id);
 }