I am building a user's resignation inside the dashboard with Form Request Validation. it works well in store resource, but I need to exclude the password role in updating resource, so if the user leaves it empty I will store the old password
my validation file
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UsersRequest extends FormRequest
{
public function rules()
{
return [
'avatar' => ['image', 'mimes:jpeg,jpg,png', 'max:700'],
'second_name' => ['required', 'max:60'],
'password' => ['required', 'confirmed', 'max:255'],
CodePudding user response:
In this case just use 'sometimes'
for updating password and not 'required'
.
public function rules()
{
return [
'avatar' => ['image', 'mimes:jpeg,jpg,png', 'max:700'],
'second_name' => ['required', 'max:60'],
'password' => ['sometimes', 'confirmed', 'max:255'],
Validating when present see docs here: sometimes rule laravel