diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 0daaeb390b..6345c67efd 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -33,7 +33,7 @@ class LocationsController extends Controller * @since [v1.0] * @return View */ - public function getIndex() + public function index() { // Grab all the locations $locations = Location::orderBy('created_at', 'DESC')->with('parent', 'assets', 'assignedassets')->get(); @@ -51,7 +51,7 @@ class LocationsController extends Controller * @since [v1.0] * @return View */ - public function getCreate() + public function create() { $locations = Location::orderBy('name', 'ASC')->get(); @@ -74,14 +74,11 @@ class LocationsController extends Controller * @since [v1.0] * @return Redirect */ - public function postCreate() + public function store() { - // create a new location instance $location = new Location(); - - // Save the location data $location->name = e(Input::get('name')); if (Input::get('parent_id')=='') { $location->parent_id = null; @@ -98,10 +95,8 @@ class LocationsController extends Controller $location->user_id = Auth::user()->id; if ($location->save()) { - // Redirect to the new location page - return redirect()->to("admin/settings/locations")->with('success', trans('admin/locations/message.create.success')); + return redirect()->route("locations.index")->with('success', trans('admin/locations/message.create.success')); } - return redirect()->back()->withInput()->withErrors($location->getErrors()); } @@ -115,7 +110,7 @@ class LocationsController extends Controller * @since [v1.0] * @return String JSON */ - public function store() + public function apiStore() { $new['currency']=Setting::first()->default_currency; @@ -156,7 +151,7 @@ class LocationsController extends Controller * @since [v1.0] * @return View */ - public function getEdit($locationId = null) + public function edit($locationId = null) { // Check if the location exists if (is_null($item = Location::find($locationId))) { @@ -182,7 +177,7 @@ class LocationsController extends Controller * @since [v1.0] * @return Redirect */ - public function postEdit($locationId = null) + public function update($locationId = null) { // Check if the location exists if (is_null($location = Location::find($locationId))) { @@ -224,7 +219,7 @@ class LocationsController extends Controller * @since [v1.0] * @return Redirect */ - public function getDelete($locationId) + public function destroy($locationId) { // Check if the location exists if (is_null($location = Location::find($locationId))) { @@ -262,7 +257,7 @@ class LocationsController extends Controller * @since [v1.0] * @return View */ - public function getView($locationId = null) + public function show($locationId = null) { $location = Location::find($locationId); @@ -332,11 +327,11 @@ class LocationsController extends Controller $rows = array(); foreach ($locations as $location) { - $actions = ''; + $actions = ''; $rows[] = array( 'id' => $location->id, - 'name' => (string)link_to('admin/settings/locations/'.$location->id.'/view', e($location->name)), + 'name' => (string)link_to_route('locations.show', e($location->name), ['location' => $location->id]), 'parent' => ($location->parent) ? e($location->parent->name) : '', // 'assets' => ($location->assets->count() + $location->assignedassets->count()), 'assets_default' => $location->assignedassets->count(), diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index c79e9e3944..720e9bdec4 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -352,7 +352,7 @@
  • - + @lang('general.locations')
  • diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php index aa692f4344..d48c345b47 100755 --- a/resources/views/locations/edit.blade.php +++ b/resources/views/locations/edit.blade.php @@ -2,7 +2,8 @@ 'createText' => trans('admin/locations/table.create') , 'updateText' => trans('admin/locations/table.update'), 'helpTitle' => trans('admin/locations/table.about_locations_title'), - 'helpText' => trans('admin/locations/table.about_locations') + 'helpText' => trans('admin/locations/table.about_locations'), + 'formAction' => ($item) ? route('locations.update', ['location' => $item->id]) : route('locations.store'), ]) {{-- Page content --}} diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.php index d97400c5cc..2f226f5701 100755 --- a/resources/views/locations/index.blade.php +++ b/resources/views/locations/index.blade.php @@ -7,7 +7,7 @@ @stop @section('header_right') - + {{ trans('general.create') }} @stop {{-- Page content --}} diff --git a/routes/web.php b/routes/web.php index 11d59b1cfa..46194494cb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -27,6 +27,14 @@ Route::resource('companies', 'CompaniesController', [ 'parameters' => ['category' => 'category_id'] ]); + /* + * Locations + */ + Route::resource('locations', 'LocationsController', [ + 'parameters' => ['location' => 'location_id'] + ]); + + /* @@ -222,23 +230,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function () ); }); - # Locations - Route::group([ 'prefix' => 'locations' ], function () { - Route::get('/', [ 'as' => 'locations', 'uses' => 'LocationsController@getIndex' ]); - Route::get('create', [ 'as' => 'create/location', 'uses' => 'LocationsController@getCreate' ]); - Route::post('create', 'LocationsController@postCreate'); - Route::get( - '{locationId}/edit', - [ 'as' => 'update/location', 'uses' => 'LocationsController@getEdit' ] - ); - Route::post('{locationId}/edit', 'LocationsController@postEdit'); - Route::get('{locationId}/view', [ 'as' => 'view/location', 'uses' => 'LocationsController@getView' ]); - Route::get( - '{locationId}/delete', - [ 'as' => 'delete/location', 'uses' => 'LocationsController@getDelete' ] - ); - }); # Status Labels Route::group([ 'prefix' => 'statuslabels' ], function () { diff --git a/tests/functional/LocationsCest.php b/tests/functional/LocationsCest.php index c6b3ff4dbc..cc38af639a 100644 --- a/tests/functional/LocationsCest.php +++ b/tests/functional/LocationsCest.php @@ -20,7 +20,7 @@ class LocationsCest /* Create Form */ $I->wantTo('Test Location Creation'); $I->lookForwardTo('Finding no Failures'); - $I->amOnPage(route('create/location')); + $I->amOnPage(route('locations.create')); $I->dontSee('Create Location', '.page-header'); $I->see('Create Location', 'h1.pull-left'); } @@ -28,7 +28,7 @@ class LocationsCest public function failsEmptyValidation(FunctionalTester $I) { $I->wantTo("Test Validation Fails with blank elements"); - $I->amOnPage(route('create/location')); + $I->amOnPage(route('locations.create')); $I->click('Save'); $I->seeElement('.alert-danger'); $I->see('The name field is required.', '.alert-msg'); @@ -37,7 +37,7 @@ class LocationsCest public function failsShortValidation(FunctionalTester $I) { $I->wantTo("Test Validation Fails with short values"); - $I->amOnPage(route('create/location')); + $I->amOnPage(route('locations.create')); $I->fillField('name', 't'); $I->click('Save'); $I->seeElement('.alert-danger'); @@ -58,7 +58,7 @@ class LocationsCest 'zip' => $location->zip, ]; $I->wantTo("Test Validation Succeeds"); - $I->amOnPage(route('create/location')); + $I->amOnPage(route('locations.create')); $I->submitForm('form#create-form', $values); $I->seeRecord('locations', $values); $I->seeElement('.alert-success'); @@ -67,7 +67,7 @@ class LocationsCest public function allowsDelete(FunctionalTester $I) { $I->wantTo('Ensure I can delete a location'); - $I->amOnPage(route('delete/location', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id)); + $I->amOnPage(route('locations.destroy', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id)); $I->seeElement('.alert-success'); } }