These three had read endpoints or nothing at all, so their content could only be changed by hand in the database. All writes are admin-only and rate limited like the existing admin routes. Testimonials are the awkward one: the migration that collapsed the legacy per-locale tables into JSON columns deliberately skipped them, so they still live in a child table. Testimonial therefore exposes a translations accessor to present the same translations[key][locale] shape as Service and Skill, which is what the generic resource form binds to. Reading the child relation has to go through getRelation(), since a plain $this->translations inside an accessor of that name re-enters the accessor and silently yields nulls. The store requests now mark the NOT NULL columns as required. Leaving them nullable let a bad payload reach the database and come back as a 500 instead of a 422, and about_me_id is additionally a cascading foreign key. Also registers the three resources with the admin read endpoint so the panel can list them, eager loading the relations their forms need.
30 lines
911 B
PHP
30 lines
911 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreServiceRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
// website_services.imageSrc is NOT NULL, so leaving it out has to be
|
|
// a 422 rather than a 500 from the database constraint.
|
|
'imageSrc' => 'required|string|max:255',
|
|
'translations' => 'required|array',
|
|
'translations.title' => 'required|array',
|
|
'translations.title.fa' => 'required|string|max:255',
|
|
'translations.title.en' => 'nullable|string|max:255',
|
|
'translations.description' => 'required|array',
|
|
'translations.description.fa' => 'required|string',
|
|
'translations.description.en' => 'nullable|string',
|
|
];
|
|
}
|
|
}
|