emilijus/bloom
Bloom is a Laravel 10 CRUD generator package. Install via composer and bloom:install to scaffold an admin dashboard, update the users table with an is_admin flag, or create an admin user. Use bloom:create to generate CRUD modules.
Installation:
composer require emilijus/bloom
php artisan vendor:publish --tag=bloom
php artisan bloom:install
First CRUD Generation:
php artisan bloom:make Post
/admin/posts to see the auto-generated CRUD interface.Key Files to Explore:
app/Providers/BloomServiceProvider.php (configures Bloom’s admin routes).config/bloom.php (customize default settings like table names, view paths).resources/views/vendor/bloom/ (override default Blade templates).php artisan bloom:make Post title:string,body:text,is_published:boolean
PostController), views (create, edit, index, show), and routes (/admin/posts).resources/views/vendor/bloom/./admin (protected by middleware).// In routes/admin.php
Bloom::resource('posts', PostController::class)->only(['index', 'store']);
@bloomFormField in Blade to render dynamic fields (e.g., @bloomFormField('title')).@bloomTable renders a paginated table with CRUD actions:
@bloomTable(Post::class, ['title', 'is_published'])
php artisan bloom:make Post --api
PostApiController with store, index, etc., methods (uses Laravel’s apiResource routes).public function test_create_post()
{
$response = $this->actingAsAdmin()->post('/admin/posts', [
'title' => 'Test Post',
'body' => 'Content...',
]);
$this->assertRedirect('/admin/posts');
}
$this->actingAsAdmin() trait (published by bloom:install).bloom:install and manually registering routes in routes/web.php:
Route::prefix('admin')->middleware(['auth', 'admin'])->group(function () {
Route::resource('posts', PostController::class);
});
App\Http\Middleware\AdminMiddleware) to add logic (e.g., role checks):
public function handle($request, Closure $next)
{
if (!auth()->user()->hasRole('superadmin')) {
abort(403);
}
return $next($request);
}
// database/seeders/PostsTableSeeder.php
public function run()
{
Post::factory()->count(10)->create();
}
DatabaseSeeder.php:
$this->call(PostsTableSeeder::class);
resources/lang/en/bloom.php:
return [
'posts' => [
'create_title' => 'Add New Article',
],
];
Breeze Dependency:
is_admin column and middleware.View Overrides:
index view:
resources/views/vendor/bloom/posts/index.blade.php
resources/views/bloom/ won’t work—use the vendor/bloom/ path.Migration Conflicts:
bloom:make may overwrite them. Use --no-migration to skip:
php artisan bloom:make Post --no-migration
Route Caching:
php artisan route:clear
Testing Quirks:
actingAsAdmin() helper requires the is_admin column. If missing, add it manually:
php artisan bloom:install --update-user-table
Log Bloom Events:
config/bloom.php:
'debug' => env('BLOOM_DEBUG', false),
storage/logs/laravel.log for generation errors.Check Generated Files:
app/Models/Post.phpapp/Http/Controllers/Admin/PostController.phpresources/views/vendor/bloom/posts/Middleware Issues:
/admin routes 403, ensure:
admin middleware is registered in app/Http/Kernel.php.is_admin column exists in users table.Custom Field Types:
php artisan vendor:publish --tag=bloom-views
app/View/Composers/BloomComposer.php.Dynamic Permissions:
// app/Policies/PostPolicy.php
public function create(User $user)
{
return $user->is_admin;
}
API Resources:
ApiResource for custom responses:
public function toArray($request, Post $post)
{
return [
'id' => $post->id,
'title' => Str::limit($post->title, 50),
];
}
Multi-Tenant Support:
resolveModel() method in PostController to scope queries by tenant:
protected function resolveModel()
{
return Tenant::query()->model()->where('tenant_id', auth()->tenant()->id);
}
Event Listeners:
created, updated) in EventServiceProvider:
protected $listen = [
'eloquent.created: App\Models\Post' => [
'App\Listeners\LogPostCreation',
],
];
How can I help you explore Laravel packages today?