Installation Add the bundle to your Laravel project via Composer:
composer require atlantic18/coral-content-bundle
Register the bundle in config/app.php under providers:
Atlantic18\CoralContentBundle\CoralContentBundle::class,
Publish Config & Migrations Run:
php artisan vendor:publish --provider="Atlantic18\CoralContentBundle\CoralContentBundle" --tag="config"
php artisan vendor:publish --provider="Atlantic18\CoralContentBundle\CoralContentBundle" --tag="migrations"
Migrate the database:
php artisan migrate
First Use Case: Creating a Content Type
Define a content type in config/coral_content.php:
'content_types' => [
'article' => [
'fields' => [
'title' => ['type' => 'text'],
'body' => ['type' => 'textarea'],
'published_at' => ['type' => 'datetime'],
],
],
],
Create a content item via Trait:
use Atlantic18\CoralContentBundle\Traits\HasCoralContent;
class Article extends Model
{
use HasCoralContent;
}
$article = Article::createContent('article', [
'title' => 'Hello World',
'body' => 'Content here...',
]);
Content Management
HasCoralContent trait to interact with content types as models.
// Fetch all articles
$articles = Article::all();
// Update content
$article->updateContent(['title' => 'Updated Title']);
versions() method to track changes:
$versions = $article->versions();
API Integration
// routes/api.php
Route::apiResource('articles', ArticleController::class);
nWidart/laravel-modules) for flexible queries:
query {
articles {
title
body
}
}
Frontend Integration
@foreach($articles as $article)
<h2>{{ $article->title }}</h2>
<div>{{ $article->body }}</div>
@endforeach
Scheduled Publishing
scheduler to auto-publish content:
// app/Console/Kernel.php
$schedule->call(function () {
\Atlantic18\CoralContentBundle\Models\Content::publishOverdue();
})->hourly();
use Laravel\Scout\Searchable;
class Article extends Model
{
use HasCoralContent, Searchable;
}
spatie/laravel-medialibrary for rich media fields:
'fields' => [
'image' => ['type' => 'media'],
],
laravel-localization.Migration Conflicts
config/coral_content.php after migrations run, manually adjust the contents table schema or drop/recreate it:
php artisan migrate:fresh
--seed to repopulate test data if needed.Content Type Validation
Content model or use Laravel's FormRequest:
use Illuminate\Validation\Rule;
public function rules()
{
return [
'title' => ['required', Rule::unique('contents')->where('type', 'article')],
];
}
Performance with Large Datasets
// Bad: Loads all versions for every article
$articles = Article::with('versions')->get();
// Good: Load only necessary versions
$article = Article::with(['versions' => function($query) {
$query->where('id', $latestVersionId);
}])->find($id);
Caching Content
Route::get('/articles', function () {
return Cache::remember('articles', now()->addHours(1), function () {
return Article::all();
});
});
Content model to log changes:
protected static function boot()
{
parent::boot();
static::updating(function ($model) {
\Log::info('Content updated', ['type' => $model->type, 'id' => $model->id]);
});
}
Custom Field Types
Extend the bundle by adding new field types in app/Providers/CoralContentServiceProvider.php:
public function register()
{
$this->app->extend('coral_content.fields', function ($fields) {
$fields['custom'] = \App\Fields\CustomField::class;
return $fields;
});
}
Content Events
Listen for content events (e.g., content.created):
// app/Providers/EventServiceProvider.php
protected $listen = [
\Atlantic18\CoralContentBundle\Events\ContentCreated::class => [
\App\Listeners\LogContentCreation::class,
],
];
Admin Panel Integration
Use backpack/laravel-backpack or filamentphp/filament to build a custom admin interface for managing content types.
Testing Use Laravel's testing helpers to assert content:
$this->assertDatabaseHas('contents', [
'type' => 'article',
'data->title' => 'Test Article',
]);
How can I help you explore Laravel packages today?