From 0769f585ea885c8eb2c84bfa78c29a7a050f8185 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 21 Oct 2019 15:45:05 -0700 Subject: [PATCH] Disallow locations from being their own parents --- app/Http/Controllers/Api/LocationsController.php | 7 +++++++ app/Http/Controllers/LocationsController.php | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 1e04fa1344..2e08472bb4 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -148,6 +148,13 @@ class LocationsController extends Controller { $this->authorize('update', Location::class); $location = Location::findOrFail($id); + + if ($request->input('parent_id') == $id) { + + return response()->json(Helper::formatStandardApiResponse('error', null, 'A location cannot be its own parent. Please select a different parent ID.')); + } + + $location->fill($request->all()); if ($location->save()) { diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index b3df9efaff..bf8a279c2e 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -145,6 +145,11 @@ class LocationsController extends Controller return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); } + if ($request->input('parent_id') == $locationId) { + return redirect()->back()->withInput()->with('error', 'A location cannot be its own parent. Please select a different parent location.'); + } + + // Update the location data $location->name = $request->input('name'); $location->parent_id = $request->input('parent_id', null);