A free open source IT asset/license management system
Change the flow of the condition using an early return
Ivan Nieto Vivanco747d6cfdb470
diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.phpindex d75921ad61..7acceb3780 100755--- a/app/Http/Controllers/Licenses/LicensesController.php+++ b/app/Http/Controllers/Licenses/LicensesController.php@@ -235,28 +235,29 @@ class LicensesController extends Controller{$license = License::with('assignedusers')->find($licenseId);- if ($license) {- $users_count = User::where('autoassign_licenses', '1')->count();- $total_seats_count = $license->totalSeatsByLicenseID();- $available_seats_count = $license->availCount()->count();- $checkedout_seats_count = ($total_seats_count - $available_seats_count);-- \Log::debug('Total: '.$total_seats_count);- \Log::debug('Users: '.$users_count);- \Log::debug('Available: '.$available_seats_count);- \Log::debug('Checkedout: '.$checkedout_seats_count);--- $this->authorize('view', $license);- return view('licenses.view', compact('license'))- ->with('users_count', $users_count)- ->with('total_seats_count', $total_seats_count)- ->with('available_seats_count', $available_seats_count)- ->with('checkedout_seats_count', $checkedout_seats_count);+ if (!$license) {+ return redirect()->route('licenses.index')+ ->with('error', trans('admin/licenses/message.does_not_exist'));}- return redirect()->route('licenses.index')- ->with('error', trans('admin/licenses/message.does_not_exist'));+ $users_count = User::where('autoassign_licenses', '1')->count();+ $total_seats_count = $license->totalSeatsByLicenseID();+ $available_seats_count = $license->availCount()->count();+ $checkedout_seats_count = ($total_seats_count - $available_seats_count);++ \Log::debug('Total: '.$total_seats_count);+ \Log::debug('Users: '.$users_count);+ \Log::debug('Available: '.$available_seats_count);+ \Log::debug('Checkedout: '.$checkedout_seats_count);+++ $this->authorize('view', $license);+ return view('licenses.view', compact('license'))+ ->with('users_count', $users_count)+ ->with('total_seats_count', $total_seats_count)+ ->with('available_seats_count', $available_seats_count)+ ->with('checkedout_seats_count', $checkedout_seats_count);+}