matrix2305 / laravel-request-object-mapper
Mapper to object from laravel request (associative array)
Installs: 3 701
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2024-12-05 23:38:25 UTC
README
Important: All properties for map must be public
Extends request class with BaseRequestObjectMapper
class CreateBannerRequest extends BaseRequestObjectMapper
Map child object in array
#[ArrayChildObjectMap(objectClass: ChildRequestClass::class)]
public array $items;
Map numeric array
#[ArrayChildTypeMap(type: ArrayChildType::FLOAT)]
public array $itemsInArray;
Laravel Object Validator
If you do before steps you can validate your properties in class by PropertyValidationRules attribute
#[PropertyValidationRules(rules: 'required|integer', messages: ['required' => 'Id is required field.'])]
public int $id;
#[PropertyValidationRules(rules: 'required|string|max:255', messages: ['required' => 'Name is required field.', 'max' => 'Name can contains maximum 255 characters.'])]
public string $name;
If validation not successfully BaseRequestObjectMapper throws FailedValidationException