/** * Authorize admin user and pass data to Dashboard. * * @return Factory|\Illuminate\View\View */ public function dash() { if (Auth::user()->is_admin) { $view_var['observations'] = FloraObserve::with(['soil', 'contributor' => function ($q) { $q->with('profile'); }])->get(); $view_var['all_observations'] = FloraObserve::count(); $view_var['all_users'] = User::count() - 1; $view_var['guest_observes'] = FloraObserve::where('user_id', '=', 2)->count(); return view('admin.dash', $view_var); } abort(401, 'Unauthorized request.'); }
/** * Show specific observation given $id * * @param $id * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($id) { $observation = FloraObserve::with(['soil', 'contributor' => function ($q) { $q->with('profile'); }])->findOrFail($id); $user_id = Auth::user()->id; $is_admin = Auth::user()->is_admin; if ($observation->user_id == $user_id || $is_admin) { return view('observation.show', compact('observation')); } abort(401, 'Unauthorized request.'); }