Installation:
composer require elasticms/core-bundle
Ensure your project uses Laravel 9.x+ (check documentation for exact compatibility).
Publish Configuration:
php artisan vendor:publish --provider="ElasticMS\CoreBundle\ElasticMSCoreBundle" --tag="config"
This generates config/elasticms.php with default settings.
Register Bundle:
Add to config/app.php under providers:
ElasticMS\CoreBundle\ElasticMSCoreBundle::class,
First Use Case:
php artisan elasticms:generate:admin --model=App\Models\Post
@ElasticMS\Api annotation to auto-generate API routes for your models.Admin Generator and API sections).php artisan elasticms to list available commands (e.g., elasticms:install, elasticms:generate:admin).config/elasticms.php for:
title, logo).api_prefix, auth_middleware).Scaffold CRUD:
php artisan elasticms:generate:admin --model=App\Models\Article --fields=id,title,content,published_at
Customize Fields: Override field types in a service provider:
// config/elasticms.php
'admin' => [
'fields' => [
'App\Models\Article' => [
'content' => \ElasticMS\CoreBundle\Form\Type\CKEditorType::class,
],
],
],
Extend Functionality:
use ElasticMS\CoreBundle\Event\AdminActionEvent;
public function onAdminAction(AdminActionEvent $event) {
if ($event->getModel() === Article::class && $event->getAction() === 'publish') {
$event->getEntity()->update(['published_at' => now()]);
}
}
ElasticMS\CoreBundle\Event\AdminListEvent.php artisan vendor:publish --provider="ElasticMS\CoreBundle\ElasticMSCoreBundle" --tag="assets"
config/elasticms.php:
'auth' => [
'driver' => 'laravel', // or 'custom'
'guard' => 'web',
],
Auto-Generate API: Annotate your model:
use ElasticMS\Api\Annotation\ApiResource;
#[ApiResource(
operations: ['index', 'store', 'show', 'update', 'destroy'],
uri: 'articles'
)]
class Article extends Model {}
Run:
php artisan elasticms:generate:api
Customize API:
use ElasticMS\CoreBundle\Serializer\Serializer;
Serializer::extend(Article::class, function (Serializer $serializer) {
$serializer->addField('custom_field', function (Article $article) {
return $article->content->excerpt();
});
});
routes/api.php:
use ElasticMS\CoreBundle\Routing\ApiRouter;
ApiRouter::resource('articles', \App\Models\Article::class);
Authentication:
Use Laravel Sanctum/Passport or configure in config/elasticms.php:
'api' => [
'auth' => [
'middleware' => 'auth:sanctum',
],
],
throttle middleware to API routes.elasticms:generate:api-docs to auto-generate Swagger/OpenAPI specs.Leverage events to hook into the core bundle’s lifecycle:
AdminListEvent: Modify list queries.AdminFormEvent: Alter form fields/validation.AdminActionEvent: Handle custom actions (e.g., bulk operations).ApiRequestEvent: Transform incoming requests.ApiResponseEvent: Modify outgoing responses.Example listener:
use ElasticMS\CoreBundle\Event\AdminListEvent;
public function onAdminList(AdminListEvent $event) {
$event->getQuery()->where('published_at', '<=', now());
}
elasticms_admin_roles). Run:
php artisan migrate
Version Mismatches:
elasticms/* packages are on the same major version.composer require elasticms/*@dev-main for bleeding-edge features.Asset Conflicts:
php artisan vendor:publish --tag=elasticms-assets) and extend the published files.Caching Issues:
php artisan view:clear
php artisan cache:clear
Eloquent Model Requirements:
ElasticMS\CoreBundle\Model\BaseModel (or implement ElasticMS\CoreBundle\Contracts\ElasticMSModel).Permission System:
admin, editor) are created on install.php artisan elasticms:install to reset permissions if corrupted.Log Level:
Enable debug mode in config/elasticms.php:
'debug' => env('APP_DEBUG', false),
Logs appear in storage/logs/elasticms.log.
Dump Events: Temporarily add a listener to dump events:
public function debugEvents(object $event) {
\Log::debug('Event:', [$event->getName(), get_class($event)]);
}
Database Queries: Use Laravel’s query logging:
\DB::enableQueryLog();
// Trigger admin/API action
\Log::info(\DB::getQueryLog());
Dynamic Configuration:
Override settings per-environment using config/elasticms.php:
'admin' => [
'title' => env('ELASTICMS_ADMIN_TITLE', 'My Admin'),
],
Multi-Tenant Support:
The bundle supports tenants via config/elasticms.php:
'tenancy' => [
'enabled' => true,
'model' => \App\Models\Tenant::class,
'tenant_key' => 'domain',
],
ElasticMS\CoreBundle\Middleware\TenantMiddleware in app/Http/Kernel.php.Localization:
Translations are stored in resources/lang/vendor/elasticms. Extend them by publishing:
php artisan vendor:publish --tag=elasticms-translations
php artisan vendor:publish --tag
How can I help you explore Laravel packages today?