PHP code example of vasichmen / laravel-handbooks

1. Go to this page and download the library: Download vasichmen/laravel-handbooks 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/ */

    

vasichmen / laravel-handbooks example snippets


'crud' => [
    'business-block' => [
        'repository' => BusinessBlockRepository::class,
        'resource' => BusinessBlockResource::class,
        'create_request' => CreateBusinessBlockRequest::class, // обязателен для create, должен подключать DTO
        'update_request' => UpdateBusinessBlockRequest::class, // обязателен для update, должен подключать DTO
        'readonly' => false,                            // только для чтения
        'searchable_fields' => ['name', 'code'],        // поля для поиска по q
        'with' => [                                     // связи, загружаемые методами list/detail/create/update
            'detail' => ['system', 'architectManagers'],
            'list' => ['system'],
        ],
        // 'view_middleware' => [...], 'create_middleware' => [...],
        // 'update_middleware' => [...], 'delete_middleware' => [...] — иначе defaults.middleware.*
    ],
],

'enums' => [
    ComponentTypeEnum::class,
    MicroserviceCodeEnum::class,
],

'dynamic' => [
    'model_base_namespace' => '\\App\\Models\\',
    'repository_base_namespace' => '\\App\\Repositories\\',
    'default_select' => ['id', 'name'],
    'default_with' => [],
    'default_searchable_fields' => ['name'],
    'custom' => [
        'system' => [
            'resource' => SystemShortResource::class,
            'select' => ['id', 'name', 'code', 'it_asset_code'],
            'with' => ['organization'],
        ],
        'user' => [
            'select' => ['id', 'name', 'login'],
            'resource' => UserShortResource::class,
        ],
    ],
],

final class EntityArchitectsRelation extends BelongsToMany implements ProvidesUniqueRelatedKeys
{
    public function getUniqueRelatedKeysQuery(): \Illuminate\Database\Query\Builder
    {
        return DB::query()->where('type', $this->architectType);
    }
}

class CreateBusinessBlockRequest extends AbstractRequest
{
    protected ?string $dtoClassName = BusinessBlockHandbookDTO::class;

    public function rules()
    {
        return [
            'name' => '

class UpdateBusinessBlockRequest extends CreateBusinessBlockRequest
{
    protected ?string $dtoClassName = BusinessBlockHandbookDTO::class;

    public function rules()
    {
        return [
            ...parent::rules(),
            'name' => [
                'sometimes',
                'string',
                'max:255',
                (new Unique(BusinessBlock::class, 'name'))->ignore($this->getRouteParameter('handbookId'))
            ],
        ];
    }
}
shell
php artisan vendor:publish --provider="Laravel\Handbooks\LaravelHandbooksServiceProvider"