refactor controllers to use form requests for validation
This commit is contained in:
49
app/Http/Requests/EducationRequest.php
Normal file
49
app/Http/Requests/EducationRequest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EducationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'opleiding' => ['required', 'string', 'max:255'],
|
||||
'instituut' => ['required', 'string', 'max:255'],
|
||||
'startdatum' => ['required', 'date'],
|
||||
'einddatum' => ['nullable', 'date', 'after_or_equal:startdatum'],
|
||||
'beschrijving' => ['nullable', 'string'],
|
||||
'afbeelding' => ['nullable', 'image', 'max:2048'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'opleiding.required' => 'De naam van de opleiding is verplicht.',
|
||||
'opleiding.string' => 'De opleiding moet een geldige tekst zijn.',
|
||||
'opleiding.max' => 'De opleiding mag maximaal 255 tekens bevatten.',
|
||||
|
||||
'instituut.required' => 'Het instituut is verplicht.',
|
||||
'instituut.string' => 'Het instituut moet een geldige tekst zijn.',
|
||||
'instituut.max' => 'Het instituut mag maximaal 255 tekens bevatten.',
|
||||
|
||||
'startdatum.required' => 'De startdatum is verplicht.',
|
||||
'startdatum.date' => 'De startdatum moet een geldige datum zijn.',
|
||||
|
||||
'einddatum.date' => 'De einddatum moet een geldige datum zijn.',
|
||||
'einddatum.after_or_equal' => 'De einddatum mag niet vóór de startdatum liggen.',
|
||||
|
||||
'beschrijving.string' => 'De beschrijving moet een geldige tekst zijn.',
|
||||
|
||||
'afbeelding.image' => 'De geüploade afbeelding moet een geldig afbeeldingsbestand zijn.',
|
||||
'afbeelding.max' => 'De afbeelding mag niet groter zijn dan 2MB.',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/PersonaliaRequest.php
Normal file
32
app/Http/Requests/PersonaliaRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PersonaliaRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'key' => ['required', 'string', 'max:255'],
|
||||
'value' => ['required', 'string', 'max:255'],
|
||||
'hidden' => ['nullable', 'boolean'],
|
||||
'icon' => ['nullable', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'key.required' => 'Een sleutel is verplicht.',
|
||||
'value.required' => 'Een waarde is verplicht.',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
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.',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
49
app/Http/Requests/WorkExperienceRequest.php
Normal file
49
app/Http/Requests/WorkExperienceRequest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class WorkExperienceRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'werkgever' => ['required', 'string', 'max:255'],
|
||||
'functie' => ['required', 'string', 'max:255'],
|
||||
'startdatum' => ['required', 'date'],
|
||||
'einddatum' => ['nullable', 'date', 'after_or_equal:startdatum'],
|
||||
'beschrijving' => ['nullable', 'string'],
|
||||
'afbeelding' => ['nullable', 'image', 'max:2048'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'werkgever.required' => 'De naam van de werkgever is verplicht.',
|
||||
'werkgever.string' => 'De werkgever moet een geldige tekst zijn.',
|
||||
'werkgever.max' => 'De werkgever mag maximaal 255 tekens bevatten.',
|
||||
|
||||
'functie.required' => 'De functietitel is verplicht.',
|
||||
'functie.string' => 'De functie moet een geldige tekst zijn.',
|
||||
'functie.max' => 'De functie mag maximaal 255 tekens bevatten.',
|
||||
|
||||
'startdatum.required' => 'De startdatum is verplicht.',
|
||||
'startdatum.date' => 'De startdatum moet een geldige datum zijn.',
|
||||
|
||||
'einddatum.date' => 'De einddatum moet een geldige datum zijn.',
|
||||
'einddatum.after_or_equal' => 'De einddatum mag niet vóór de startdatum liggen.',
|
||||
|
||||
'beschrijving.string' => 'De beschrijving moet een geldige tekst zijn.',
|
||||
|
||||
'afbeelding.image' => 'De afbeelding moet een geldig afbeeldingsbestand zijn.',
|
||||
'afbeelding.max' => 'De afbeelding mag niet groter zijn dan 2MB.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user