<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
macropay-solutions / laravel-crud-wizard-free example snippets
class DbCrudMap
{
public const MODEL_FQN_TO_CONTROLLER_MAP = [
BaseModelChild::class => ResourceControllerTraitIncludedChild::class,
...
];
}
#OperationModel example for BaseModelFrozenAttributes
public function getFrozen(): OperationFrozenAttributes
{
return parent::getFrozen(); // this is needed for autocompletion and will tes((clone $this)->forceFill($this->attributesToArray()));
}
#OperationService example for BaseModelAttributes and BaseModelFrozenAttributes
public function someFunction(): void
{
// BaseModelAttributes
echo $this->model-a->value; // has autocomplete - will print for example 1
echo $this->model-a->value = 10; // has autocomplete - will print 10
echo $this->model->value; // has autocomplete - will print 10
// BaseModelFrozenAttributes
$dto = $this->model->getFrozen();
echo $dto->client_id; // has autocomplete - will print for example 1
$dto->client_id = 4; // Exception: Dynamic properties are forbidden.
if (isset($dto->client)) {
/** @var ClientFrozenAttributes $client */
// $client will be an stdClass that has autocomplete like a ClientFrozenAttributes
$client = $dto->client;
echo $client->name; // has autocomplete - will print for example 'name'
$client->name = 'text'; // NO Exception
echo $client->name; // will print 'text'
// $client changes can happen, but they will not be persisted in the $dto ($client is a stdClass clone)
echo $dto->client->name; // will print 'name'
}
foreach (($dto->products ?? []) as $k => $product) {
/** @var ProductFrozenAttributes $product */
// $product will be an stdClass that has autocompletes like a ProductFrozenAttributes
echo $product->value; // has autocomplete - will print for example 1
$product->value = 2; // NO Exception
echo $product->value; // will print 2
// $product changes can happen, but they will not be persisted in the $dto ($product is a stdClass clone)
echo $dto->products[$k]->name; // will print 1
}
}