orderBy('id', 'desc')->get(); $activeKey = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->first(); if (!$fetchKeys->isEmpty()) { if ($activeKey->created_at->addWeek()->gt(Carbon::now())) { $canCreate = false; } else { $canCreate = true; } } else { $canCreate = true; } $data = [ 'canCreate' => $canCreate, 'fetchKeys' => $fetchKeys, ]; return view('invite.index')->with('data', $data); } public function create() { $fetchKeys = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->get(); $activeKey = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->first(); // Validation if (!$fetchKeys->isEmpty() && $activeKey->created_at->addWeek()->gt(Carbon::now())) { if (!User::isAdmin()) abort(404); } $key = new InviteKey; $key->key = Uuid::generate()->string; $key->created_by = Auth::id(); $key->user_invited = 0; $key->save(); return redirect()->route('key_index'); } }