Declare variables only if license is found

This commit is contained in:
Ivan Nieto Vivanco 2023-04-20 10:16:11 -06:00
parent 4a5426f959
commit ae53609b1b

View file

@ -234,6 +234,8 @@ class LicensesController extends Controller
public function show($licenseId = null) public function show($licenseId = null)
{ {
$license = License::with('assignedusers')->find($licenseId); $license = License::with('assignedusers')->find($licenseId);
if ($license) {
$users_count = User::where('autoassign_licenses', '1')->count(); $users_count = User::where('autoassign_licenses', '1')->count();
$total_seats_count = $license->totalSeatsByLicenseID(); $total_seats_count = $license->totalSeatsByLicenseID();
$available_seats_count = $license->availCount()->count(); $available_seats_count = $license->availCount()->count();
@ -245,7 +247,6 @@ class LicensesController extends Controller
\Log::debug('Checkedout: '.$checkedout_seats_count); \Log::debug('Checkedout: '.$checkedout_seats_count);
if ($license) {
$this->authorize('view', $license); $this->authorize('view', $license);
return view('licenses.view', compact('license')) return view('licenses.view', compact('license'))
->with('users_count', $users_count) ->with('users_count', $users_count)
@ -254,7 +255,7 @@ class LicensesController extends Controller
->with('checkedout_seats_count', $checkedout_seats_count); ->with('checkedout_seats_count', $checkedout_seats_count);
} }
return redirect()->route('licenses.view') return redirect()->route('licenses.index')
->with('error', trans('admin/licenses/message.does_not_exist')); ->with('error', trans('admin/licenses/message.does_not_exist'));
} }