Add support for JSON requests
This commit is contained in:
parent
4133efb8a8
commit
0d1787d69a
1 changed files with 14 additions and 9 deletions
|
@ -16,21 +16,26 @@ class PlaceService
|
|||
*/
|
||||
public function createPlace(Request $request)
|
||||
{
|
||||
//we’ll either have latitude and longitude sent together in a
|
||||
//geo-url (micropub), or seperatley (/admin)
|
||||
if ($request->input('geo') !== null) {
|
||||
$parts = explode(':', $request->input('geo'));
|
||||
$latlng = explode(',', $parts[1]);
|
||||
$latitude = $latlng[0];
|
||||
$longitude = $latlng[1];
|
||||
if ($request->header('Content-Type') == 'application/json') {
|
||||
$name = $request->input('properties.name');
|
||||
$description = $request->input('properties.description') ?? null;
|
||||
$geo = $request->input('properties.geo');
|
||||
} else {
|
||||
$name = $request->input('name');
|
||||
$description = $request->input('description');
|
||||
$geo = $request->input('geo');
|
||||
}
|
||||
$parts = explode(':', $geo);
|
||||
$latlng = explode(',', $parts[1]);
|
||||
$latitude = $latlng[0];
|
||||
$longitude = $latlng[1];
|
||||
if ($request->input('latitude') !== null) {
|
||||
$latitude = $request->input('latitude');
|
||||
$longitude = $request->input('longitude');
|
||||
}
|
||||
$place = new Place();
|
||||
$place->name = $request->input('name');
|
||||
$place->description = $request->input('description');
|
||||
$place->name = $name;
|
||||
$place->description = $description;
|
||||
$place->location = new Point((float) $latitude, (float) $longitude);
|
||||
$place->save();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue