Ejemplo n.º 1
0
 public function afterSave($event)
 {
     $model = $this->owner;
     $es = $this->path_elements[$model->path];
     foreach ($es as $value) {
         $place = new Place();
         $place->title = $value;
         $place->layout_id = $model->id;
         $place->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * store a resource 
  * @param  Request 	$request http request
  * @param  mixed  	$id      id of the resource for updating
  * @return jsend           	 jsend with newly stored source
  */
 function store(Request $request, $id = null)
 {
     ////////////////
     // Load Data  //
     ////////////////
     if ($id) {
         $data = Model::find($id);
         if (!$data) {
             return app()->abort(404);
         }
     } else {
         $data = new Model();
     }
     ///////////////////////////////////
     // Assign posted data to Data    //
     ///////////////////////////////////
     $data->fill($request->input());
     ///////////////////////////////////////////////////////////////////
     // 							Validate data 						 //
     ///////////////////////////////////////////////////////////////////
     # Validate Destinations
     $destination_id = null;
     if ($request->input('destination_id') && is_string($request->input('destination_id'))) {
         $destination = Destination::find($request->input('destination_id'));
         if ($destination) {
             $destination_id = $request->input('destination_id');
         } else {
             return response()->json(JSend::fail('InvalidDestination : Destination not found')->asArray());
         }
     } elseif (!is_string($request->input('destination_id'))) {
         return response()->json(JSend::fail('InvalidDestination : Invalid Destination format')->asArray());
     } else {
         return response()->json(JSend::fail('InvalidDestination : Destination is required')->asArray());
     }
     ///////////////////////////
     // Embeds Other Document //
     ///////////////////////////
     $data->images = $request->input('images');
     $data->tags = is_array($request->input('tags')) ? $request->input('tags') : [$request->input('tags')];
     $data->destination_id = $destination_id;
     ///////////
     // Store //
     ///////////
     if ($data->save()) {
         return response()->json(JSend::success(['data' => $data])->asArray());
     } else {
         return response()->json(JSend::fail($data->getErrors())->asArray());
     }
 }
Ejemplo n.º 3
0
 public static function createPlace($place_name, $place_address, $lat, $lng)
 {
     $check = Place::where('name', $place_name)->first();
     if ($check) {
         return $check['attributes']['place_id'];
     } else {
         $place = new Place();
         $place->name = $place_name;
         $place->address = $place_address;
         $place->lat = $lat;
         $place->lng = $lng;
         $place->save();
         return $place['attributes']['id'];
     }
 }
Ejemplo n.º 4
0
 public function addPlace($data, $location_id)
 {
     $mplace = new Place();
     $mplace->location_id = $location_id;
     $attributes = (array) $data;
     $mplace->setAttributes($attributes);
     $mplace->lat = $data->geometry->location->lat;
     $mplace->lng = $data->geometry->location->lng;
     if ($mplace->save()) {
         $this->addCategory($data->types, $mplace);
         if (isset($data->photos)) {
             $this->addPhoto($data->photos, $mplace);
         }
     }
     return $mplace;
 }