MIF_E31222307/app/Http/Requests/UpdateUserRequest.php

34 lines
996 B
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest 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
{
return [
'name' => 'required|string|max:100',
'email' => 'required|email|unique:users,email,' . Auth::id(), // Ensure the user ID is passed correctly
'no_telp' => 'required|string|max:20',
'password' => 'nullable|string|min:6', // Password is optional, only validated if present
'role_id' => 'required|exists:roles,id', // Ensures 'role_id' exists in the 'roles' table
];
}
}