From 06b500984250f75b98f38a8f25ac953cb45aeee4 Mon Sep 17 00:00:00 2001
From: Dan Brown <ssddanbrown@googlemail.com>
Date: Fri, 5 Nov 2021 00:26:55 +0000
Subject: [PATCH] Standardised laravel validation to be array based

Converted from string-only-based validation.
Array based validation works nicer once you have validation classess or
advanced validation options.
---
 app/Api/ApiDocsGenerator.php                  |  8 ++-----
 .../Api/AttachmentApiController.php           | 16 ++++++-------
 .../Controllers/Api/BookApiController.php     | 12 +++++-----
 .../Api/BookshelfApiController.php            | 12 +++++-----
 .../Controllers/Api/ChapterApiController.php  | 16 ++++++-------
 .../Controllers/Api/PageApiController.php     | 24 +++++++++----------
 app/Http/Controllers/AttachmentController.php | 18 +++++++-------
 .../Auth/ConfirmEmailController.php           |  2 +-
 .../Auth/ForgotPasswordController.php         |  4 +++-
 app/Http/Controllers/Auth/LoginController.php |  8 +++----
 .../Auth/MfaBackupCodesController.php         |  3 +--
 .../Controllers/Auth/RegisterController.php   |  6 ++---
 .../Controllers/Auth/UserInviteController.php |  2 +-
 app/Http/Controllers/BookController.php       | 12 +++++-----
 app/Http/Controllers/BookshelfController.php  | 12 +++++-----
 app/Http/Controllers/ChapterController.php    |  2 +-
 app/Http/Controllers/CommentController.php    |  6 ++---
 app/Http/Controllers/Controller.php           |  4 ++--
 app/Http/Controllers/FavouriteController.php  |  4 ++--
 .../Images/DrawioImageController.php          |  4 ++--
 .../Controllers/Images/ImageController.php    |  2 +-
 app/Http/Controllers/PageController.php       |  6 ++---
 app/Http/Controllers/RoleController.php       |  4 ++--
 app/Http/Controllers/SettingController.php    |  2 +-
 .../Controllers/UserApiTokenController.php    |  8 +++----
 app/Http/Controllers/UserController.php       | 18 +++++++-------
 26 files changed, 106 insertions(+), 109 deletions(-)

diff --git a/app/Api/ApiDocsGenerator.php b/app/Api/ApiDocsGenerator.php
index 0ed7e6712..3aabfb4cc 100644
--- a/app/Api/ApiDocsGenerator.php
+++ b/app/Api/ApiDocsGenerator.php
@@ -95,17 +95,13 @@ class ApiDocsGenerator
         }
 
         $rules = $class->getValdationRules()[$methodName] ?? [];
-        foreach ($rules as $param => $ruleString) {
-            $rules[$param] = explode('|', $ruleString);
-        }
-
-        return count($rules) > 0 ? $rules : null;
+        return empty($rules) ? null : $rules;
     }
 
     /**
      * Parse out the description text from a class method comment.
      */
-    protected function parseDescriptionFromMethodComment(string $comment)
+    protected function parseDescriptionFromMethodComment(string $comment): string
     {
         $matches = [];
         preg_match_all('/^\s*?\*\s((?![@\s]).*?)$/m', $comment, $matches);
diff --git a/app/Http/Controllers/Api/AttachmentApiController.php b/app/Http/Controllers/Api/AttachmentApiController.php
index 06d9f6907..67815bc47 100644
--- a/app/Http/Controllers/Api/AttachmentApiController.php
+++ b/app/Http/Controllers/Api/AttachmentApiController.php
@@ -17,16 +17,16 @@ class AttachmentApiController extends ApiController
 
     protected $rules = [
         'create' => [
-            'name'        => 'required|min:1|max:255|string',
-            'uploaded_to' => 'required|integer|exists:pages,id',
-            'file'        => 'required_without:link|file',
-            'link'        => 'required_without:file|min:1|max:255|safe_url',
+            'name'        => ['required', 'min:1', 'max:255', 'string'],
+            'uploaded_to' => ['required', 'integer', 'exists:pages,id'],
+            'file'        => ['required_without:link', 'file'],
+            'link'        => ['required_without:file', 'min:1', 'max:255', 'safe_url'],
         ],
         'update' => [
-            'name'        => 'min:1|max:255|string',
-            'uploaded_to' => 'integer|exists:pages,id',
-            'file'        => 'file',
-            'link'        => 'min:1|max:255|safe_url',
+            'name'        => ['min:1', 'max:255', 'string'],
+            'uploaded_to' => ['integer', 'exists:pages,id'],
+            'file'        => ['file'],
+            'link'        => ['min:1', 'max:255', 'safe_url'],
         ],
     ];
 
diff --git a/app/Http/Controllers/Api/BookApiController.php b/app/Http/Controllers/Api/BookApiController.php
index abe23f45d..b28e3eefa 100644
--- a/app/Http/Controllers/Api/BookApiController.php
+++ b/app/Http/Controllers/Api/BookApiController.php
@@ -13,14 +13,14 @@ class BookApiController extends ApiController
 
     protected $rules = [
         'create' => [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'tags'        => 'array',
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'tags'        => ['array'],
         ],
         'update' => [
-            'name'        => 'string|min:1|max:255',
-            'description' => 'string|max:1000',
-            'tags'        => 'array',
+            'name'        => ['string', 'min:1', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'tags'        => ['array'],
         ],
     ];
 
diff --git a/app/Http/Controllers/Api/BookshelfApiController.php b/app/Http/Controllers/Api/BookshelfApiController.php
index c29e5b0ae..de7284e61 100644
--- a/app/Http/Controllers/Api/BookshelfApiController.php
+++ b/app/Http/Controllers/Api/BookshelfApiController.php
@@ -18,14 +18,14 @@ class BookshelfApiController extends ApiController
 
     protected $rules = [
         'create' => [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'books'       => 'array',
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'books'       => ['array'],
         ],
         'update' => [
-            'name'        => 'string|min:1|max:255',
-            'description' => 'string|max:1000',
-            'books'       => 'array',
+            'name'        => ['string', 'min:1', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'books'       => ['array'],
         ],
     ];
 
diff --git a/app/Http/Controllers/Api/ChapterApiController.php b/app/Http/Controllers/Api/ChapterApiController.php
index 13b3f9821..6b226b5f0 100644
--- a/app/Http/Controllers/Api/ChapterApiController.php
+++ b/app/Http/Controllers/Api/ChapterApiController.php
@@ -14,16 +14,16 @@ class ChapterApiController extends ApiController
 
     protected $rules = [
         'create' => [
-            'book_id'     => 'required|integer',
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'tags'        => 'array',
+            'book_id'     => ['required', 'integer'],
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'tags'        => ['array'],
         ],
         'update' => [
-            'book_id'     => 'integer',
-            'name'        => 'string|min:1|max:255',
-            'description' => 'string|max:1000',
-            'tags'        => 'array',
+            'book_id'     => ['integer'],
+            'name'        => ['string', 'min:1', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'tags'        => ['array'],
         ],
     ];
 
diff --git a/app/Http/Controllers/Api/PageApiController.php b/app/Http/Controllers/Api/PageApiController.php
index f698627a7..6f3a71e02 100644
--- a/app/Http/Controllers/Api/PageApiController.php
+++ b/app/Http/Controllers/Api/PageApiController.php
@@ -16,20 +16,20 @@ class PageApiController extends ApiController
 
     protected $rules = [
         'create' => [
-            'book_id'    => 'required_without:chapter_id|integer',
-            'chapter_id' => 'required_without:book_id|integer',
-            'name'       => 'required|string|max:255',
-            'html'       => 'required_without:markdown|string',
-            'markdown'   => 'required_without:html|string',
-            'tags'       => 'array',
+            'book_id'    => ['required_without:chapter_id', 'integer'],
+            'chapter_id' => ['required_without:book_id', 'integer'],
+            'name'       => ['required', 'string', 'max:255'],
+            'html'       => ['required_without:markdown', 'string'],
+            'markdown'   => ['required_without:html', 'string'],
+            'tags'       => ['array'],
         ],
         'update' => [
-            'book_id'    => 'required|integer',
-            'chapter_id' => 'required|integer',
-            'name'       => 'string|min:1|max:255',
-            'html'       => 'string',
-            'markdown'   => 'string',
-            'tags'       => 'array',
+            'book_id'    => ['required', 'integer'],
+            'chapter_id' => ['required', 'integer'],
+            'name'       => ['string', 'min:1', 'max:255'],
+            'html'       => ['string'],
+            'markdown'   => ['string'],
+            'tags'       => ['array'],
         ],
     ];
 
diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php
index c08247dad..ec9872bcf 100644
--- a/app/Http/Controllers/AttachmentController.php
+++ b/app/Http/Controllers/AttachmentController.php
@@ -36,8 +36,8 @@ class AttachmentController extends Controller
     public function upload(Request $request)
     {
         $this->validate($request, [
-            'uploaded_to' => 'required|integer|exists:pages,id',
-            'file'        => 'required|file',
+            'uploaded_to' => ['required', 'integer', 'exists:pages,id'],
+            'file'        => ['required', 'file'],
         ]);
 
         $pageId = $request->get('uploaded_to');
@@ -65,7 +65,7 @@ class AttachmentController extends Controller
     public function uploadUpdate(Request $request, $attachmentId)
     {
         $this->validate($request, [
-            'file' => 'required|file',
+            'file' => ['required', 'file'],
         ]);
 
         /** @var Attachment $attachment */
@@ -111,8 +111,8 @@ class AttachmentController extends Controller
 
         try {
             $this->validate($request, [
-                'attachment_edit_name' => 'required|string|min:1|max:255',
-                'attachment_edit_url'  => 'string|min:1|max:255|safe_url',
+                'attachment_edit_name' => ['required', 'string', 'min:1', 'max:255'],
+                'attachment_edit_url'  => ['string', 'min:1', 'max:255', 'safe_url'],
             ]);
         } catch (ValidationException $exception) {
             return response()->view('attachments.manager-edit-form', array_merge($request->only(['attachment_edit_name', 'attachment_edit_url']), [
@@ -146,9 +146,9 @@ class AttachmentController extends Controller
 
         try {
             $this->validate($request, [
-                'attachment_link_uploaded_to' => 'required|integer|exists:pages,id',
-                'attachment_link_name'        => 'required|string|min:1|max:255',
-                'attachment_link_url'         => 'required|string|min:1|max:255|safe_url',
+                'attachment_link_uploaded_to' => ['required', 'integer', 'exists:pages,id'],
+                'attachment_link_name'        => ['required', 'string', 'min:1', 'max:255'],
+                'attachment_link_url'         => ['required', 'string', 'min:1', 'max:255', 'safe_url'],
             ]);
         } catch (ValidationException $exception) {
             return response()->view('attachments.manager-link-form', array_merge($request->only(['attachment_link_name', 'attachment_link_url']), [
@@ -195,7 +195,7 @@ class AttachmentController extends Controller
     public function sortForPage(Request $request, int $pageId)
     {
         $this->validate($request, [
-            'order' => 'required|array',
+            'order' => ['required', 'array'],
         ]);
         $page = $this->pageRepo->getById($pageId);
         $this->checkOwnablePermission('page-update', $page);
diff --git a/app/Http/Controllers/Auth/ConfirmEmailController.php b/app/Http/Controllers/Auth/ConfirmEmailController.php
index 02b9ef276..c5466aecd 100644
--- a/app/Http/Controllers/Auth/ConfirmEmailController.php
+++ b/app/Http/Controllers/Auth/ConfirmEmailController.php
@@ -107,7 +107,7 @@ class ConfirmEmailController extends Controller
     public function resend(Request $request)
     {
         $this->validate($request, [
-            'email' => 'required|email|exists:users,email',
+            'email' => ['required', 'email', 'exists:users,email'],
         ]);
         $user = $this->userRepo->getByEmail($request->get('email'));
 
diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php
index 8eaee08a2..212bb6ab1 100644
--- a/app/Http/Controllers/Auth/ForgotPasswordController.php
+++ b/app/Http/Controllers/Auth/ForgotPasswordController.php
@@ -43,7 +43,9 @@ class ForgotPasswordController extends Controller
      */
     public function sendResetLinkEmail(Request $request)
     {
-        $this->validate($request, ['email' => 'required|email']);
+        $this->validate($request, [
+            'email' => ['required', 'email']
+        ]);
 
         // We will send the password reset link to this user. Once we have attempted
         // to send the link, we will examine the response then see the message we
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index d12d7c9bc..427d88a02 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -176,16 +176,16 @@ class LoginController extends Controller
      */
     protected function validateLogin(Request $request)
     {
-        $rules = ['password' => 'required|string'];
+        $rules = ['password' => ['required', 'string']];
         $authMethod = config('auth.method');
 
         if ($authMethod === 'standard') {
-            $rules['email'] = 'required|email';
+            $rules['email'] = ['required', 'email'];
         }
 
         if ($authMethod === 'ldap') {
-            $rules['username'] = 'required|string';
-            $rules['email'] = 'email';
+            $rules['username'] = ['required', 'string'];
+            $rules['email'] = ['email'];
         }
 
         $request->validate($rules);
diff --git a/app/Http/Controllers/Auth/MfaBackupCodesController.php b/app/Http/Controllers/Auth/MfaBackupCodesController.php
index d92029bf1..e24090022 100644
--- a/app/Http/Controllers/Auth/MfaBackupCodesController.php
+++ b/app/Http/Controllers/Auth/MfaBackupCodesController.php
@@ -73,8 +73,7 @@ class MfaBackupCodesController extends Controller
 
         $this->validate($request, [
             'code' => [
-                'required',
-                'max:12', 'min:8',
+                'required', 'max:12', 'min:8',
                 function ($attribute, $value, $fail) use ($codeService, $codes) {
                     if (!$codeService->inputCodeExistsInSet($value, $codes)) {
                         $fail(trans('validation.backup_codes'));
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 209827d6d..d4e7fcb8e 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -68,9 +68,9 @@ class RegisterController extends Controller
     protected function validator(array $data)
     {
         return Validator::make($data, [
-            'name'     => 'required|min:2|max:255',
-            'email'    => 'required|email|max:255|unique:users',
-            'password' => 'required|min:8',
+            'name'     => ['required', 'min:2', 'max:255'],
+            'email'    => ['required', 'email', 'max:255', 'unique:users'],
+            'password' => ['required', 'min:8'],
         ]);
     }
 
diff --git a/app/Http/Controllers/Auth/UserInviteController.php b/app/Http/Controllers/Auth/UserInviteController.php
index bd1912b0b..b3ccf072a 100644
--- a/app/Http/Controllers/Auth/UserInviteController.php
+++ b/app/Http/Controllers/Auth/UserInviteController.php
@@ -58,7 +58,7 @@ class UserInviteController extends Controller
     public function setPassword(Request $request, string $token)
     {
         $this->validate($request, [
-            'password' => 'required|min:8',
+            'password' => ['required', 'min:8'],
         ]);
 
         try {
diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php
index 7c099377c..af44a6689 100644
--- a/app/Http/Controllers/BookController.php
+++ b/app/Http/Controllers/BookController.php
@@ -85,9 +85,9 @@ class BookController extends Controller
     {
         $this->checkPermission('book-create-all');
         $this->validate($request, [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'image'       => 'nullable|' . $this->getImageValidationRules(),
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         $bookshelf = null;
@@ -156,9 +156,9 @@ class BookController extends Controller
         $book = $this->bookRepo->getBySlug($slug);
         $this->checkOwnablePermission('book-update', $book);
         $this->validate($request, [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'image'       => 'nullable|' . $this->getImageValidationRules(),
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         $book = $this->bookRepo->update($book, $request->all());
diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php
index da16d7822..32248ee46 100644
--- a/app/Http/Controllers/BookshelfController.php
+++ b/app/Http/Controllers/BookshelfController.php
@@ -84,9 +84,9 @@ class BookshelfController extends Controller
     {
         $this->checkPermission('bookshelf-create-all');
         $this->validate($request, [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'image'       => 'nullable|' . $this->getImageValidationRules(),
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         $bookIds = explode(',', $request->get('books', ''));
@@ -161,9 +161,9 @@ class BookshelfController extends Controller
         $shelf = $this->bookshelfRepo->getBySlug($slug);
         $this->checkOwnablePermission('bookshelf-update', $shelf);
         $this->validate($request, [
-            'name'        => 'required|string|max:255',
-            'description' => 'string|max:1000',
-            'image'       => 'nullable|' . $this->getImageValidationRules(),
+            'name'        => ['required', 'string', 'max:255'],
+            'description' => ['string', 'max:1000'],
+            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         $bookIds = explode(',', $request->get('books', ''));
diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php
index b27fb4f77..9d2bd2489 100644
--- a/app/Http/Controllers/ChapterController.php
+++ b/app/Http/Controllers/ChapterController.php
@@ -47,7 +47,7 @@ class ChapterController extends Controller
     public function store(Request $request, string $bookSlug)
     {
         $this->validate($request, [
-            'name' => 'required|string|max:255',
+            'name' => ['required', 'string', 'max:255'],
         ]);
 
         $book = Book::visible()->where('slug', '=', $bookSlug)->firstOrFail();
diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php
index dfe468f5f..9804f6d39 100644
--- a/app/Http/Controllers/CommentController.php
+++ b/app/Http/Controllers/CommentController.php
@@ -24,8 +24,8 @@ class CommentController extends Controller
     public function savePageComment(Request $request, int $pageId)
     {
         $this->validate($request, [
-            'text'      => 'required|string',
-            'parent_id' => 'nullable|integer',
+            'text'      => ['required', 'string'],
+            'parent_id' => ['nullable', 'integer'],
         ]);
 
         $page = Page::visible()->find($pageId);
@@ -53,7 +53,7 @@ class CommentController extends Controller
     public function update(Request $request, int $commentId)
     {
         $this->validate($request, [
-            'text' => 'required|string',
+            'text' => ['required', 'string'],
         ]);
 
         $comment = $this->commentRepo->getById($commentId);
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index d63280a23..df450d051 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -175,8 +175,8 @@ abstract class Controller extends BaseController
     /**
      * Get the validation rules for image files.
      */
-    protected function getImageValidationRules(): string
+    protected function getImageValidationRules(): array
     {
-        return 'image_extension|mimes:jpeg,png,gif,webp';
+        return ['image_extension', 'mimes:jpeg,png,gif,webp'];
     }
 }
diff --git a/app/Http/Controllers/FavouriteController.php b/app/Http/Controllers/FavouriteController.php
index a990ff825..c8ba3078c 100644
--- a/app/Http/Controllers/FavouriteController.php
+++ b/app/Http/Controllers/FavouriteController.php
@@ -69,8 +69,8 @@ class FavouriteController extends Controller
     protected function getValidatedModelFromRequest(Request $request): Favouritable
     {
         $modelInfo = $this->validate($request, [
-            'type' => 'required|string',
-            'id'   => 'required|integer',
+            'type' => ['required', 'string'],
+            'id'   => ['required', 'integer'],
         ]);
 
         if (!class_exists($modelInfo['type'])) {
diff --git a/app/Http/Controllers/Images/DrawioImageController.php b/app/Http/Controllers/Images/DrawioImageController.php
index b8e4546ff..cab1c925e 100644
--- a/app/Http/Controllers/Images/DrawioImageController.php
+++ b/app/Http/Controllers/Images/DrawioImageController.php
@@ -44,8 +44,8 @@ class DrawioImageController extends Controller
     public function create(Request $request)
     {
         $this->validate($request, [
-            'image'       => 'required|string',
-            'uploaded_to' => 'required|integer',
+            'image'       => ['required', 'string'],
+            'uploaded_to' => ['required', 'integer'],
         ]);
 
         $this->checkPermission('image-create-all');
diff --git a/app/Http/Controllers/Images/ImageController.php b/app/Http/Controllers/Images/ImageController.php
index 231712d52..21ed58553 100644
--- a/app/Http/Controllers/Images/ImageController.php
+++ b/app/Http/Controllers/Images/ImageController.php
@@ -51,7 +51,7 @@ class ImageController extends Controller
     public function update(Request $request, string $id)
     {
         $this->validate($request, [
-            'name' => 'required|min:2|string',
+            'name' => ['required', 'min:2', 'string'],
         ]);
 
         $image = $this->imageRepo->getById($id);
diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php
index ddb15a7aa..7d5d93ffa 100644
--- a/app/Http/Controllers/PageController.php
+++ b/app/Http/Controllers/PageController.php
@@ -60,7 +60,7 @@ class PageController extends Controller
     public function createAsGuest(Request $request, string $bookSlug, string $chapterSlug = null)
     {
         $this->validate($request, [
-            'name' => 'required|string|max:255',
+            'name' => ['required', 'string', 'max:255'],
         ]);
 
         $parent = $this->pageRepo->getParentFromSlugs($bookSlug, $chapterSlug);
@@ -107,7 +107,7 @@ class PageController extends Controller
     public function store(Request $request, string $bookSlug, int $pageId)
     {
         $this->validate($request, [
-            'name' => 'required|string|max:255',
+            'name' => ['required', 'string', 'max:255'],
         ]);
         $draftPage = $this->pageRepo->getById($pageId);
         $this->checkOwnablePermission('page-create', $draftPage->getParent());
@@ -234,7 +234,7 @@ class PageController extends Controller
     public function update(Request $request, string $bookSlug, string $pageSlug)
     {
         $this->validate($request, [
-            'name' => 'required|string|max:255',
+            'name' => ['required', 'string', 'max:255'],
         ]);
         $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
         $this->checkOwnablePermission('page-update', $page);
diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php
index 06a30e99d..7ba52d486 100644
--- a/app/Http/Controllers/RoleController.php
+++ b/app/Http/Controllers/RoleController.php
@@ -48,7 +48,7 @@ class RoleController extends Controller
     {
         $this->checkPermission('user-roles-manage');
         $this->validate($request, [
-            'display_name' => 'required|min:3|max:180',
+            'display_name' => ['required', 'min:3', 'max:180'],
             'description'  => 'max:180',
         ]);
 
@@ -83,7 +83,7 @@ class RoleController extends Controller
     {
         $this->checkPermission('user-roles-manage');
         $this->validate($request, [
-            'display_name' => 'required|min:3|max:180',
+            'display_name' => ['required', 'min:3', 'max:180'],
             'description'  => 'max:180',
         ]);
 
diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php
index d9f172081..b12b0e3ce 100644
--- a/app/Http/Controllers/SettingController.php
+++ b/app/Http/Controllers/SettingController.php
@@ -44,7 +44,7 @@ class SettingController extends Controller
         $this->preventAccessInDemoMode();
         $this->checkPermission('settings-manage');
         $this->validate($request, [
-            'app_logo' => 'nullable|' . $this->getImageValidationRules(),
+            'app_logo' => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         // Cycles through posted settings and update them
diff --git a/app/Http/Controllers/UserApiTokenController.php b/app/Http/Controllers/UserApiTokenController.php
index bdc25f79d..b1a043cd3 100644
--- a/app/Http/Controllers/UserApiTokenController.php
+++ b/app/Http/Controllers/UserApiTokenController.php
@@ -36,8 +36,8 @@ class UserApiTokenController extends Controller
         $this->checkPermissionOrCurrentUser('users-manage', $userId);
 
         $this->validate($request, [
-            'name'       => 'required|max:250',
-            'expires_at' => 'date_format:Y-m-d',
+            'name'       => ['required', 'max:250'],
+            'expires_at' => ['date_format:Y-m-d'],
         ]);
 
         $user = User::query()->findOrFail($userId);
@@ -86,8 +86,8 @@ class UserApiTokenController extends Controller
     public function update(Request $request, int $userId, int $tokenId)
     {
         $this->validate($request, [
-            'name'       => 'required|max:250',
-            'expires_at' => 'date_format:Y-m-d',
+            'name'       => ['required', 'max:250'],
+            'expires_at' => ['date_format:Y-m-d'],
         ]);
 
         [$user, $token] = $this->checkPermissionAndFetchUserToken($userId, $tokenId);
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 2ee303f3f..414bfefeb 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -74,18 +74,18 @@ class UserController extends Controller
     {
         $this->checkPermission('users-manage');
         $validationRules = [
-            'name'  => 'required',
-            'email' => 'required|email|unique:users,email',
+            'name'  => ['required'],
+            'email' => ['required', 'email', 'unique:users,email'],
         ];
 
         $authMethod = config('auth.method');
         $sendInvite = ($request->get('send_invite', 'false') === 'true');
 
         if ($authMethod === 'standard' && !$sendInvite) {
-            $validationRules['password'] = 'required|min:6';
-            $validationRules['password-confirm'] = 'required|same:password';
+            $validationRules['password'] = ['required', 'min:6'];
+            $validationRules['password-confirm'] = ['required', 'same:password'];
         } elseif ($authMethod === 'ldap' || $authMethod === 'saml2' || $authMethod === 'openid') {
-            $validationRules['external_auth_id'] = 'required';
+            $validationRules['external_auth_id'] = ['required'];
         }
         $this->validate($request, $validationRules);
 
@@ -156,11 +156,11 @@ class UserController extends Controller
 
         $this->validate($request, [
             'name'             => 'min:2',
-            'email'            => 'min:2|email|unique:users,email,' . $id,
-            'password'         => 'min:6|required_with:password_confirm',
-            'password-confirm' => 'same:password|required_with:password',
+            'email'            => ['min:2', 'email', 'unique:users,email,' . $id],
+            'password'         => ['min:6', 'required_with:password_confirm'],
+            'password-confirm' => ['same:password', 'required_with:password'],
             'setting'          => 'array',
-            'profile_image'    => 'nullable|' . $this->getImageValidationRules(),
+            'profile_image'    => array_merge(['nullable'], $this->getImageValidationRules()),
         ]);
 
         $user = $this->userRepo->getById($id);