Skip to content

Commit 9fdac12

Browse files
authored
Session flash notices (#19)
* Update Notice component and Inertia handler to user session flash message * Remove usage of custom notice session array
1 parent 284e8f8 commit 9fdac12

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

app/Http/Controllers/AccountController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public function update(AccountUpdate $request)
2020
$request->user()->update($request->only('first_name', 'last_name', 'email'));
2121
$request->user()->updatePassword($request->validated('password'));
2222

23-
return \redirect()->back()->with('notice', [
24-
'type' => 'success',
25-
'message' => 'Your account has been updated.',
26-
]);
23+
\session()->flash('message', 'Your account has been updated.');
24+
25+
return \redirect()->back();
2726
}
2827
}

app/Http/Middleware/HandleInertiaRequests.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ public function share(Request $request): array
1414
'auth' => [
1515
'user' => $request->user() ? UserResource::make($request->user()) : [],
1616
],
17-
'notice' => $request->session()->get('notice') ?: [
18-
'type' => '',
19-
'message' => '',
20-
],
17+
'message' => $request->session()->get('message'),
2118
]);
2219
}
2320
}

resources/js/Components/Notice.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
},
1919
2020
watch: {
21-
"$page.props.notice": {
21+
"$page.props.message": {
2222
handler() {
23-
this.setNotice(router.page.props.notice, "success");
23+
this.setNotice(router.page.props.message, "success");
2424
},
2525
},
2626
"$page.props.errors": {
@@ -48,10 +48,10 @@
4848
},
4949
5050
methods: {
51-
setNotice(notice, type) {
52-
if (type && notice.message != "") {
51+
setNotice(message, type) {
52+
if (type && message != "") {
5353
this.type = type;
54-
this.message = notice.message;
54+
this.message = message;
5555
5656
this.setActive();
5757
}

0 commit comments

Comments
 (0)