2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
2017-02-18 21:36:22 +00:00
|
|
|
namespace App\Http\Controllers\Admin;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
use App\Place;
|
|
|
|
use Illuminate\Http\Request;
|
2017-03-01 20:15:35 +00:00
|
|
|
use App\Services\PlaceService;
|
2017-02-18 21:36:22 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Phaza\LaravelPostgis\Geometries\Point;
|
|
|
|
|
|
|
|
class PlacesAdminController extends Controller
|
|
|
|
{
|
2017-03-01 20:15:35 +00:00
|
|
|
protected $placeService;
|
|
|
|
|
|
|
|
public function __construct(PlaceService $placeService = null)
|
|
|
|
{
|
|
|
|
$this->placeService = $placeService ?? new PlaceService();
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
/**
|
|
|
|
* List the places that can be edited.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-18 21:36:22 +00:00
|
|
|
public function index()
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
$places = Place::all();
|
|
|
|
|
|
|
|
return view('admin.listplaces', ['places' => $places]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form to make a new place.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-18 21:36:22 +00:00
|
|
|
public function create()
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
return view('admin.newplace');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the form to edit a specific place.
|
|
|
|
*
|
|
|
|
* @param string The place id
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-18 21:36:22 +00:00
|
|
|
public function edit($placeId)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
$place = Place::findOrFail($placeId);
|
|
|
|
|
|
|
|
$latitude = $place->getLatitude();
|
|
|
|
$longitude = $place->getLongitude();
|
|
|
|
|
|
|
|
return view('admin.editplace', [
|
|
|
|
'id' => $placeId,
|
|
|
|
'name' => $place->name,
|
|
|
|
'description' => $place->description,
|
|
|
|
'latitude' => $latitude,
|
|
|
|
'longitude' => $longitude,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a request to make a new place.
|
|
|
|
*
|
|
|
|
* @param Illuminate\Http\Request $request
|
|
|
|
* @return Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-18 21:36:22 +00:00
|
|
|
public function store(Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-03-01 20:15:35 +00:00
|
|
|
$data = [];
|
|
|
|
$data['name'] = $request->name;
|
|
|
|
$data['description'] = $request->description;
|
|
|
|
$data['latitude'] = $request->latitude;
|
|
|
|
$data['longitude'] = $request->longitude;
|
|
|
|
$place = $this->placeService->createPlace($data);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
return view('admin.newplacesuccess');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a request to edit a place.
|
|
|
|
*
|
|
|
|
* @param string The place id
|
|
|
|
* @param Illuminate\Http\Request $request
|
|
|
|
* @return Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-18 21:36:22 +00:00
|
|
|
public function update($placeId, Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
$place = Place::findOrFail($placeId);
|
|
|
|
$place->name = $request->name;
|
|
|
|
$place->description = $request->description;
|
|
|
|
$place->location = new Point((float) $request->latitude, (float) $request->longitude);
|
|
|
|
$place->save();
|
|
|
|
|
|
|
|
return view('admin.editplacesuccess');
|
|
|
|
}
|
|
|
|
}
|