Ejemplo n.º 1
0
 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);
 }