Check for valid location before trying to print

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-06-03 16:56:15 -07:00
parent 07b1062fb2
commit dba06a3a9e

View file

@ -211,23 +211,35 @@ class LocationsController extends Controller
public function print_assigned($id) public function print_assigned($id)
{ {
$location = Location::where('id', $id)->first();
if ($location = Location::where('id', $id)->first()) {
$parent = Location::where('id', $location->parent_id)->first(); $parent = Location::where('id', $location->parent_id)->first();
$manager = User::where('id', $location->manager_id)->first(); $manager = User::where('id', $location->manager_id)->first();
$users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); $users = User::where('location_id', $id)->with('company', 'department', 'location')->get();
$assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get(); $assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get();
return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager);
}
return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist'));
} }
public function print_all_assigned($id) public function print_all_assigned($id)
{ {
$location = Location::where('id', $id)->first(); if ($location = Location::where('id', $id)->first()) {
$parent = Location::where('id', $location->parent_id)->first(); $parent = Location::where('id', $location->parent_id)->first();
$manager = User::where('id', $location->manager_id)->first(); $manager = User::where('id', $location->manager_id)->first();
$users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); $users = User::where('location_id', $id)->with('company', 'department', 'location')->get();
$assets = Asset::where('location_id', $id)->with('model', 'model.category')->get(); $assets = Asset::where('location_id', $id)->with('model', 'model.category')->get();
return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager);
}
return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist'));
} }
} }