refactor controllers to use form requests for validation
This commit is contained in:
33
app/Http/Requests/SkillRequest.php
Normal file
33
app/Http/Requests/SkillRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SkillRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'rating' => ['required', 'numeric', 'min:1', 'max:10'],
|
||||
'image' => ['nullable', 'image', 'max:2048'],
|
||||
'type' => ['required', 'in:rating,tag,other'],
|
||||
];
|
||||
}
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => 'Een titel is verplicht.',
|
||||
'rating.required' => 'Geef een beoordeling tussen 1 en 10.',
|
||||
'type.in' => 'Het type moet rating, tag of other zijn.',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user