diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 74a37364..52057914 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -167,28 +167,28 @@ class UserController extends Controller */ public function notify(Request $request, User $user) { - $via = $request->validate([ + $data = $request->validate([ "via" => "required|min:1|array", "via.*" => "required|string|in:mail,database", - ])["via"]; + "title" => "required|string|min:1", + "content" => "required|string|min:1" + ]); $mail = null; $database = null; - if (in_array('database', $via)) { - $database = $request->validate([ - "title" => "required|string|min:1", - "content" => "required|string|min:1" - ]); + if (in_array('database', $data["via"])) { + $database = [ + "title" => $data["title"], + "content" => $data["content"] + ]; } - if (in_array('mail', $via)) { - $data = $request->validate([ - "subject" => "required|string|min:1", - "body" => "required|string|min:1" - ]); - $mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"])); + if (in_array('mail', $data["via"])) { + $mail = (new MailMessage) + ->subject($data["title"]) + ->line(new HtmlString($data["content"])); } $user->notify( - new DynamicNotification($via, $database, $mail) + new DynamicNotification($data["via"], $database, $mail) ); return redirect()->route('admin.users.notifications', $user->id)->with('success', 'User notified!'); } diff --git a/app/Http/Controllers/Api/NotificationController.php b/app/Http/Controllers/Api/NotificationController.php index 68c52c90..a5bf3084 100644 --- a/app/Http/Controllers/Api/NotificationController.php +++ b/app/Http/Controllers/Api/NotificationController.php @@ -61,24 +61,24 @@ class NotificationController extends Controller $discordUser = DiscordUser::find($userId); $user = $discordUser ? $discordUser->user : User::findOrFail($userId); - $via = $request->validate([ - "via" => ["required", new Delimited("in:mail,database")] + $data = $request->validate([ + "via" => ["required", new Delimited("in:mail,database")], + "title" => "required|string|min:1", + "content" => "required|string|min:1" ]); - $via = explode(',', $via["via"]); + $via = explode(',', $data["via"]); $mail = null; $database = null; if (in_array('database', $via)) { - $database = $request->validate([ - "title" => "required|string|min:1", - "content" => "required|string|min:1" - ]); + $database = [ + "title" => $data["title"], + "content" => $data["content"] + ]; } if (in_array('mail', $via)) { - $data = $request->validate([ - "subject" => "required|string|min:1", - "body" => "required|string|min:1" - ]); - $mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"])); + $mail = (new MailMessage) + ->subject($data["title"]) + ->line(new HtmlString($data["content"])); } $user->notify( new DynamicNotification($via, $database, $mail) diff --git a/resources/views/admin/users/notifications.blade.php b/resources/views/admin/users/notifications.blade.php index a8f8b69d..b3474ba2 100644 --- a/resources/views/admin/users/notifications.blade.php +++ b/resources/views/admin/users/notifications.blade.php @@ -36,13 +36,11 @@