public function getMessages(Request $request) { $user = User::where('id', $request->user()->id)->first(); $threads = Thread::forUser($request->user()->id)->orderBy('updated_at', 'desc')->simplePaginate(10); if ($user && $threads) { $title = 'Cообщения'; return view('messages.index')->withThreads($threads)->withUser($user)->withTitle($title); } else { return redirect()->route('messages')->withError('Ошибка, свяжитесь с администратором.'); } }
public function index() { $currentUserId = Auth::user()->id; $threads = Thread::forUser($currentUserId)->latest('updated_at')->get(); return view('messages', compact('threads')); }