-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from ManiruzzamanAkash/akash/change/refactor-r…
…equest-files Refactor Request files for better validation and improve some UX
- Loading branch information
Showing
9 changed files
with
143 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class AdminRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
$adminId = $this->route('admin'); | ||
|
||
return [ | ||
'name' => 'required|max:50', | ||
'email' => 'required|max:100|email|unique:admins,email,' . $adminId, | ||
'username' => 'required|max:100|unique:admins,username,' . $adminId, | ||
'password' => $adminId ? 'nullable|min:6|confirmed' : 'required|min:6|confirmed', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class RoleRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
$roleId = $this->route('role'); | ||
|
||
return [ | ||
'name' => 'required|max:100|unique:roles,name,' . $roleId, | ||
'permissions' => 'required|array|min:1', | ||
'permissions.*' => 'string|exists:permissions,name', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.