* * @version v1.0 */ class DashboardController extends Controller { /** * Check authorization and display admin dashboard, otherwise display * the user's checked-out assets. * * @author [A. Gianotto] [] * * @since [v1.0] */ public function index(): View|RedirectResponse { // Show the page if (auth()->user()->hasAccess('admin')) { $asset_stats = null; $counts['asset'] = Asset::count(); $counts['accessory'] = Accessory::count(); $counts['license'] = License::assetcount(); $counts['consumable'] = Consumable::count(); $counts['component'] = Component::count(); $counts['user'] = Company::scopeCompanyables(auth()->user())->count(); $counts['grand_total'] = $counts['asset'] + $counts['accessory'] + $counts['license'] + $counts['consumable']; if ((! file_exists(storage_path().'/oauth-private.key')) || (! file_exists(storage_path().'/oauth-public.key'))) { Artisan::call('migrate', ['--force' => true]); Artisan::call('passport:install', ['--no-interaction' => true]); } return view('dashboard')->with('asset_stats', $asset_stats)->with('counts', $counts); } else { Session::reflash(); // Redirect to the profile page return redirect()->intended('account/view-assets'); } } }