|
4 | 4 | use Cmgmyr\Messenger\Models\Thread; |
5 | 5 | use Cmgmyr\Messenger\Models\Message; |
6 | 6 | use Cmgmyr\Messenger\Models\Participant; |
| 7 | +use Illuminate\Database\Eloquent\ModelNotFoundException; |
7 | 8 | use Illuminate\Support\Facades\Auth; |
| 9 | +use Illuminate\Support\Facades\Input; |
| 10 | +use Illuminate\Support\Facades\Redirect; |
| 11 | +use Illuminate\Support\Facades\Session; |
| 12 | +use Illuminate\Support\Facades\View; |
8 | 13 |
|
9 | 14 | class MessagesController extends BaseController |
10 | 15 | { |
@@ -47,7 +52,13 @@ public function index() |
47 | 52 | */ |
48 | 53 | public function show($id) |
49 | 54 | { |
50 | | - $thread = Thread::findOrFail($id); |
| 55 | + try { |
| 56 | + $thread = Thread::findOrFail($id); |
| 57 | + } catch (ModelNotFoundException $e) { |
| 58 | + Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.'); |
| 59 | + |
| 60 | + return Redirect::to('messages'); |
| 61 | + } |
51 | 62 |
|
52 | 63 | // show current user in list if not a current participant |
53 | 64 | // $users = User::whereNotIn('id', $thread->participantsUserIds())->get(); |
@@ -122,7 +133,13 @@ public function store() |
122 | 133 | */ |
123 | 134 | public function update($id) |
124 | 135 | { |
125 | | - $thread = Thread::findOrFail($id); |
| 136 | + try { |
| 137 | + $thread = Thread::findOrFail($id); |
| 138 | + } catch (ModelNotFoundException $e) { |
| 139 | + Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.'); |
| 140 | + |
| 141 | + return Redirect::to('messages'); |
| 142 | + } |
126 | 143 |
|
127 | 144 | $thread->activateAllParticipants(); |
128 | 145 |
|
|
0 commit comments