feat(profile): align settings with dashboard layout
This commit is contained in:
31
app/Http/Requests/Profile/UpdatePasswordRequest.php
Normal file
31
app/Http/Requests/Profile/UpdatePasswordRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Profile;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules;
|
||||
|
||||
class UpdatePasswordRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->user();
|
||||
|
||||
return [
|
||||
'current_password' => $user->hasPassword()
|
||||
? ['required', 'string', 'current_password:web']
|
||||
: ['nullable', 'string'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
47
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Profile;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateProfileRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => ['required', 'string', 'max:255'],
|
||||
'last_name' => ['required', 'string', 'max:255'],
|
||||
'username' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
'alpha_dash',
|
||||
function ($attribute, $value, $fail): void {
|
||||
if (User::whereKeyNot($this->user()->getKey())
|
||||
->whereRaw('LOWER(username) = ?', [strtolower($value)])
|
||||
->exists()) {
|
||||
$fail('The username has already been taken.');
|
||||
}
|
||||
},
|
||||
],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->getKey()),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user