file-management-system/app/Http/Requests/UpdateDirectoratRequest.php

48 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2023-04-11 09:21:20 +00:00
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
2023-04-12 10:06:33 +00:00
use Illuminate\Validation\Validator;
2023-04-11 09:21:20 +00:00
class UpdateDirectoratRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
2023-04-12 10:06:33 +00:00
return true;
2023-04-11 09:21:20 +00:00
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
2023-04-12 10:06:33 +00:00
'kode' => 'required|string|max:2|min:2|unique:directorats,kode,'.$this->id,
'name' => 'required|string|max:50'
2023-04-11 09:21:20 +00:00
];
}
2023-04-12 10:06:33 +00:00
/**
* Configure the validator instance.
*/
public function withValidator(Validator $validator): void
{
$validator->after(function (Validator $validator) {
if($validator->errors()->any()) {
$error = json_decode($validator->errors()->toJson(), true);
foreach ($error as $key => $value) {
flash( $value[0]);
}
return redirect()->route('directorat.index')->with('error', 'Directorat updated failed.');
}
});
}
2023-04-11 09:21:20 +00:00
}