crud user
This commit is contained in:
58
app/Http/Requests/UserRequest.php
Normal file
58
app/Http/Requests/UserRequest.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
// public function authorize(): bool
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required|unique:user,username|min:5|max:255',
|
||||
'password' => 'required|min:6|max:255',
|
||||
'email' => 'required|email|unique:user,email|max:255',
|
||||
'user_photo' => ''
|
||||
];
|
||||
}
|
||||
|
||||
public static function rulesForUpdate(FormRequest $formRequest, User $user): \Illuminate\Validation\Validator
|
||||
{
|
||||
return Validator::make($formRequest->all(), [
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('user', 'email')->ignore($user->email, 'email'),
|
||||
],
|
||||
'username' => [
|
||||
'required',
|
||||
'min:5',
|
||||
'max:255',
|
||||
Rule::unique('user', 'username')->ignore($user->username, 'username'),
|
||||
],
|
||||
'password' => [
|
||||
'min:6',
|
||||
'max:255',
|
||||
'nullable',
|
||||
],
|
||||
'user_photo' => []
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user