digipolisgent/domainator9k-apptype-laravel-bundle
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,
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.
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']],
],
],
],
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'));
}
}
App Type Management
$allTypes = $this->appTypeService->getAllAppTypes();
$webApp = $this->appTypeService->getAppType('web_app');
$isValid = $this->appTypeService->validateAppTypeData('web_app', $request->all());
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.
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();
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...
}
$this->app->bind(Domainator9kApptypeService::class, function ($app) {
return new Domainator9kApptypeService($app['config']['domainator9k-apptype']);
});
validateAppTypeData method in a custom service.'name' => trans('app_types.web_app.name'),
Deprecated Symfony Bundle
No Database Migrations
app_types) with fields like type, data (JSON), and created_at.Config Overrides
Resources/config/services.yml for missing keys.Blade Directive Scope
@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.getFormFields method.Service Not Found
config/app.php.config/domainator9k-apptype.php.dd($this->app->getBindings());
Validation Errors
ValidatorInterface. If you encounter issues, replace it with Laravel’s Validator:
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($data, $rules);
Field Rendering Issues
fields array in the config is correctly formatted (e.g., ['type' => 'text']).<form method="POST">).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);
}
}
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
}
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'] ?? [],
];
}
}
getAllAppTypes() result if the config rarely changes:
$appTypes = Cache::remember('domainator9k.app_types', now()->addHours(1), function () {
return $this->appTypeService->getAllAppTypes();
});
How can I help you explore Laravel packages today?