PHP code example of macropay-solutions / laravel-crud-wizard-decorator-free
1. Go to this page and download the library: Download macropay-solutions/laravel-crud-wizard-decorator-free library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
macropay-solutions / laravel-crud-wizard-decorator-free example snippets
$app->routeMiddleware([
'decorate-' . \MacropaySolutions\LaravelCrudWizardDecorator\Models\ExampleModel::resourceName()=>
MacropaySolutions\LaravelCrudWizardDecorator\Http\Middleware\Decorators\ExampleMiddleware::class,
]);
'decorate-' . $resourceName . ':list'
'decorate-' . $resourceName . ':get'
'decorate-' . $resourceName . ':getRelated'
'decorate-' . $resourceName . ':update'
'decorate-' . $resourceName . ':updateRelated'
'decorate-' . $resourceName . ':create'
'decorate-' . $resourceName . ':delete'
'decorate-' . $resourceName . ':deleteRelated'
namespace MacropaySolutions\LaravelCrudWizardDecorator\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use MacropaySolutions\LaravelCrudWizard\Models\BaseModel;
class ExampleModel extends BaseModel
{
public const RESOURCE_NAME = 'examples';
protected $fillable = [
'role_id',
'created_at',
'updated_at',
];
public function roleRelation(): HasOne
{
return $this->hasOne(RelationExampleModel::class, 'id', 'role_id');
}
}
namespace MacropaySolutions\LaravelCrudWizardDecorator\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use MacropaySolutions\LaravelCrudWizard\Models\BaseModel;
class RelationExampleModel extends BaseModel
{
public const RESOURCE_NAME = 'relation-examples';
protected $fillable = [
'name',
'color',
'created_at',
'updated_at',
];
public function exampleModels(): HasMany
{
return $this->hasMany(ExampleModel::class, 'role_id', 'id');
}
}
namespace MacropaySolutions\LaravelCrudWizardDecorator\Http\Middleware\Decorators;
use MacropaySolutions\LaravelCrudWizardDecorator\Decorators\ExampleDecorator;
use MacropaySolutions\LaravelCrudWizardDecorator\Decorators\RelationExampleDecorator;
class ExampleMiddleware extends AbstractDecoratorMiddleware
{
protected string $decoratorClass = ExampleDecorator::class;
protected array $relatedDecoratorClassMap = [
'roleRelation' => RelationExampleDecorator::class
];
public function setResourceModel(): void
{
$this->resourceModel = new ExampleModel();
}
}
namespace MacropaySolutions\LaravelCrudWizardDecorator\Http\Middleware\Decorators;
use MacropaySolutions\LaravelCrudWizardDecorator\Decorators\ExampleDecorator;
use MacropaySolutions\LaravelCrudWizardDecorator\Decorators\RelationExampleDecorator;
class RelationExampleMiddleware extends AbstractDecoratorMiddleware
{
protected string $decoratorClass = RelationExampleDecorator::class;
protected array $relatedDecoratorClassMap = [
'exampleModels' => ExampleDecorator::class
];
public function setResourceModel(): void
{
$this->resourceModel = new RelationExampleModel();
}
}
namespace MacropaySolutions\LaravelCrudWizardDecorator\Decorators;
class ExampleDecorator extends AbstractResourceDecorator
{
public function getResourceMappings(): array
{
return [
'id' => 'ID',
'updated_at' => 'updatedAt',
'created_at' => 'createdAt',
];
}
/**
* @inheritDoc
*/
public function getRelationMappings(): array
{
return [
'roleRelation' => [
'name' => 'roleRelationName',
'color' => 'roleRelationColor',
],
];
}
}
namespace MacropaySolutions\LaravelCrudWizardDecorator\Decorators;
class RelationExampleDecorator extends AbstractResourceDecorator
{
public array $countRelations = ['exampleModels'];
public array $existRelations = ['exampleModels'];
public function getResourceMappings(): array
{
return [
'id' => 'ID',
'name' => 'roleName',
'color' => 'roleColor',
'updated_at' => 'updatedAt',
'created_at' => 'createdAt',
];
}
}