user_id = Auth::user()->id; $shituser->description = $request->description; $shituser->goldenshit = $request->goldenshit == "on"; // Get the latest shit event and check if it is over a time threshold $lastshit = ShitUser::where('user_id', $shituser->user_id)->orderByDesc('created_at')->first(); $timethreshold = Carbon::now()->subMinutes(10); if (is_null($lastshit) || $lastshit->created_at->lessThan($timethreshold)) { $shituser->save(); return redirect('/ownstats'); } else { return redirect('/dashboard'); } } public function ownStats() { $shits = ShitUser::where('user_id', Auth::user()->id)->get(); $amountshits = $shits->count(); $goldenshits = $shits->where('goldenshit', true)->count(); return view('ownstats')->with([ 'amountshits' => $amountshits, 'goldenshits' => $goldenshits, ]); } public function highscores() { $allshits = ShitUser::groupBy('user_id')->select('user_id', DB::raw('count (*) as total'))->orderByDesc('total')->get(); $users = User::all()->sortBy('name'); return view('highscores')->with([ 'allshits' => $allshits, 'users' => $users, ]); } }