Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Domainator9K Apptype Laravel Bundle Laravel Package

digipolisgent/domainator9k-apptype-laravel-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require district09/domainator9k-apptype-laravel-bundle
    

    Register the bundle in config/app.php under providers:

    District09\Domainator9kApptypeBundle\Domainator9kApptypeBundle::class,
    
  2. Publish Configuration Publish the default config:

    php artisan vendor:publish --provider="District09\Domainator9kApptypeBundle\Domainator9kApptypeBundle" --tag="config"
    

    Locate the config file at config/domainator9k-apptype.php.

  3. First Use Case: Define an App Type Define a custom app type in the config:

    'app_types' => [
        'web_app' => [
            'name' => 'Web Application',
            'description' => 'A standard web application',
            'icon' => 'fas fa-globe',
            'fields' => [
                'url' => ['type' => 'text', 'label' => 'Application URL'],
                'framework' => ['type' => 'select', 'label' => 'Framework', 'options' => ['laravel', 'symfony', 'other']],
            ],
        ],
    ],
    
  4. Create a Controller Inject the service into a controller:

    use District09\Domainator9kApptypeBundle\Services\Domainator9kApptypeService;
    
    class AppTypeController extends Controller
    {
        protected $appTypeService;
    
        public function __construct(Domainator9kApptypeService $appTypeService)
        {
            $this->appTypeService = $appTypeService;
        }
    
        public function index()
        {
            $appTypes = $this->appTypeService->getAllAppTypes();
            return view('app_types.index', compact('appTypes'));
        }
    }
    

Implementation Patterns

Core Workflows

  1. App Type Management

    • Retrieve All Types:
      $allTypes = $this->appTypeService->getAllAppTypes();
      
    • Retrieve a Single Type:
      $webApp = $this->appTypeService->getAppType('web_app');
      
    • Validate App Type Data:
      $isValid = $this->appTypeService->validateAppTypeData('web_app', $request->all());
      
  2. Form Integration Use the app_type_form Blade directive to render fields dynamically:

    @app_type_form('web_app', $appData)
    

    This auto-generates fields based on the config.

  3. Storing App Type Data Use a model to store app type instances (e.g., AppType):

    $appType = new AppType();
    $appType->type = 'web_app';
    $appType->data = $request->all();
    $appType->save();
    
  4. API Endpoints Create RESTful endpoints for app type CRUD:

    // Example: Store an app type instance
    public function store(Request $request)
    {
        $validated = $this->appTypeService->validateAppTypeData($request->type, $request->all());
        // Save to DB...
    }
    

Integration Tips

  • Laravel Service Container: Bind the service manually if autowiring fails:
    $this->app->bind(Domainator9kApptypeService::class, function ($app) {
        return new Domainator9kApptypeService($app['config']['domainator9k-apptype']);
    });
    
  • Validation: Extend the default validator by overriding the validateAppTypeData method in a custom service.
  • Localization: Use Laravel’s localization features to translate app type names/descriptions:
    'name' => trans('app_types.web_app.name'),
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Bundle

    • The package is a Symfony bundle adapted for Laravel. Some Symfony-specific assumptions (e.g., dependency injection, event system) may not align perfectly.
    • Fix: Override the service class to adapt to Laravel’s DI container or use interfaces for abstraction.
  2. No Database Migrations

    • The package lacks built-in migrations for storing app type instances. You must create your own table (e.g., app_types) with fields like type, data (JSON), and created_at.
  3. Config Overrides

    • The config file is published but may not include all possible options. Always check the original bundle’s Resources/config/services.yml for missing keys.
  4. Blade Directive Scope

    • The @app_type_form directive assumes it’s used within a Laravel Blade template. Using it in non-Blade contexts (e.g., API responses) will fail.
    • Fix: Manually render fields using the service’s getFormFields method.

Debugging

  1. Service Not Found

    • If the service isn’t autowired, check:
      • The bundle is registered in config/app.php.
      • The config file exists at config/domainator9k-apptype.php.
    • Debug: Dump the service container bindings:
      dd($this->app->getBindings());
      
  2. Validation Errors

    • The validator uses Symfony’s ValidatorInterface. If you encounter issues, replace it with Laravel’s Validator:
      use Illuminate\Support\Facades\Validator;
      
      $validator = Validator::make($data, $rules);
      
  3. Field Rendering Issues

    • If fields don’t render, verify:
      • The fields array in the config is correctly formatted (e.g., ['type' => 'text']).
      • The Blade directive is placed inside a form tag (e.g., <form method="POST">).

Extension Points

  1. Custom Field Types Extend the package by adding custom field renderers. Override the getFieldRenderer method in a child service class:

    class CustomDomainator9kApptypeService extends Domainator9kApptypeService
    {
        public function getFieldRenderer($type)
        {
            if ($type === 'custom_field') {
                return new CustomFieldRenderer();
            }
            return parent::getFieldRenderer($type);
        }
    }
    
  2. Event Listeners The original Symfony bundle uses events (e.g., domainator9k.apptype.create). Replicate this in Laravel using events:

    // In a listener:
    public function handle(AppTypeCreated $event)
    {
        // Logic here
    }
    
  3. API Resources Transform app type data into API responses using Laravel’s ApiResource:

    class AppTypeResource extends JsonResource
    {
        public function toArray($request)
        {
            return [
                'type' => $this->type,
                'data' => $this->data,
                'fields' => app(Domainator9kApptypeService::class)->getAppType($this->type)['fields'] ?? [],
            ];
        }
    }
    

Performance Tips

  • Cache App Types: Cache the getAllAppTypes() result if the config rarely changes:
    $appTypes = Cache::remember('domainator9k.app_types', now()->addHours(1), function () {
        return $this->appTypeService->getAllAppTypes();
    });
    
  • Lazy-Load Fields: Load form fields only when needed (e.g., in a view) to reduce memory usage.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium