creonit/admin-bundle
AdminBundle by Creonit is a PHP admin panel bundle for building back-office interfaces. It provides a structured way to define admin modules, screens, and forms, aiming to speed up CRUD-style administration and internal tools development.
Installation
composer require creonit/admin-bundle
Add to config/app.php under providers:
Creonit\AdminBundle\AdminBundle::class,
Publish the bundle's assets and config:
php artisan vendor:publish --provider="Creonit\AdminBundle\AdminBundle" --tag=config
php artisan vendor:publish --provider="Creonit\AdminBundle\AdminBundle" --tag=assets
Basic Configuration
Edit config/admin.php to define your admin routes and middleware:
'routes' => [
'prefix' => 'admin',
'middleware' => ['web', 'auth.admin'], // Custom middleware required
],
First Use Case: CRUD Controller
Generate a scaffolded controller for a model (e.g., User):
php artisan admin:make:controller User --model=App\Models\User
This creates a controller with index, create, store, edit, update, destroy methods pre-configured.
Dynamic Admin Panels
Use the @adminPanel directive in Blade templates to render admin-specific layouts:
@adminPanel
<div class="admin-header">Dashboard</div>
@yield('admin_content')
@endadminPanel
Model Integration
Extend Creonit\AdminBundle\Controller\AbstractAdminController for custom logic:
class UserAdminController extends AbstractAdminController
{
protected $model = User::class;
public function index()
{
$users = $this->model::paginate(10);
return view('admin.users.index', compact('users'));
}
}
Form Handling Leverage the bundle’s form helpers for admin-specific fields:
$form = $this->createFormBuilder($user)
->add('name', TextType::class, ['admin_label' => 'Full Name'])
->add('email', EmailType::class, ['admin_hint' => 'Required'])
->getForm();
Access Control
Use the canAccess method to restrict routes:
public function destroy($id)
{
if (!$this->canAccess('delete_user')) {
abort(403);
}
// Delete logic...
}
Asset Management Override default assets by publishing and extending:
php artisan vendor:publish --provider="Creonit\AdminBundle\AdminBundle" --tag=public
Then extend resources/admin/scss/admin.scss.
webpack.mix.js:
mix.js('resources/admin/js/admin.js', 'public/admin/js')
.sass('resources/admin/scss/admin.scss', 'public/admin/css');
spatie/laravel-permission for role-based access:
// In AdminBundle config
'middleware' => ['web', 'auth', 'permission:admin-access'],
resources/lang/vendor/admin.AdminResponse for consistent JSON responses:
return new AdminResponse(['success' => true, 'data' => $users]);
Middleware Dependency
auth.admin middleware (not included). Implement it via:
Route::middleware('auth.admin', function ($request, $next) {
if (!auth()->user()->isAdmin()) abort(403);
return $next($request);
});
Asset Paths
// config/admin.php
'assets' => [
'css' => 'admin/css/custom.css',
'js' => 'admin/js/custom.js',
],
Form Validation
$this->validate($request, [
'field' => 'required|admin_rule:custom_rule',
]);
Define admin_rule in AppServiceProvider.Route Caching
php artisan route:clear
Deprecated Methods
// Avoid if present
$this->admin()->getModel(); // Use $this->model directly
php artisan route:list --path=admin
.env:
DEBUG_BLADE=true
storage/logs/laravel.log:
\Log::error('Admin form errors:', $form->getErrors());
Custom Directives
Extend Blade directives in AppServiceProvider:
Blade::directive('adminPanel', function ($expression) {
return "<?php echo Creonit\AdminBundle\Blade\AdminPanel::render($expression); ?>";
});
Event Listeners
Listen to admin events (e.g., admin.user.created):
event(new AdminUserCreated($user));
Register in EventServiceProvider.
Service Providers Bind custom services to the bundle’s container:
$this->app->bind('admin.custom_service', function () {
return new CustomAdminService();
});
Database Observers Extend model observers for admin-specific logic:
User::observe(AdminUserObserver::class);
API Resources Create custom admin API resources:
class AdminUserResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'admin_meta' => $this->adminMeta(),
];
}
}
How can I help you explore Laravel packages today?