-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Improvements:
- Defined Properties
- Nesting is simple
- Would simplify the transform code to a function
- Would allow two way transform (ie. from request, handy for forms)
- Possibility to add Mutatators / Attributes
- Could handle Subclassing with
parent::fromCar() - Allows a little reuse ie. for dropdown data
namespace App\ViewObject;
use FocalStrategy\ViewObjects\ViewObject;
use App\Models\Car;
class CarVo extends ViewObject
{
protected $car_id;
protected $make;
protected $model;
/* @nested(AssessmentVo) */
protected $assessments;
public function fromCar(Car $car)
{
$this->car_id = $car->id;
$this->make = $car->marque->display_name ?? 'Not Set';
$this->model = $car->modelBasic->display_name ?? 'Not Set';
$this->withNested('assessments', $car->car_assessment_results);
}
public function fromArray($req_data)
{
$this->car_id = $req_data['id'];
$this->make = $req_data['make'];
$this->model = $req_data['model'];
$this->withNested('assessments', $req_data['assessments']);
}
}
Metadata
Metadata
Assignees
Labels
No labels