brix/admin-bundle
Brix AdminBundle provides the administration bundle for BrixCMS, adding core tools and integration needed to manage and operate a BrixCMS site from an admin interface.
Installation
composer require brix/admin-bundle
Add to config/app.php under providers:
Brix\AdminBundle\AdminBundle::class,
Publish assets and config:
php artisan vendor:publish --provider="Brix\AdminBundle\AdminBundle" --tag=config
php artisan vendor:publish --provider="Brix\AdminBundle\AdminBundle" --tag=assets
Basic Admin Route
Register a controller in routes/web.php:
use Brix\AdminBundle\Controller\AdminController;
Route::prefix('admin')->group(function () {
Route::get('/', [AdminController::class, 'index']);
});
First Admin Page
Create a simple admin page by extending AdminController:
namespace App\Http\Controllers\Admin;
use Brix\AdminBundle\Controller\AdminController;
class DashboardController extends AdminController
{
public function index()
{
return $this->render('admin/dashboard', [
'title' => 'Dashboard',
]);
}
}
Register the route:
Route::get('/dashboard', [DashboardController::class, 'index']);
Blade Template
Create resources/views/admin/dashboard.blade.php:
@extends('admin::layout')
@section('content')
<h1>{{ $title }}</h1>
<p>Welcome to the admin panel!</p>
@endsection
Generate a CRUD Controller Use Artisan to scaffold a CRUD controller:
php artisan make:crud Post --model=Post --controller=Admin/PostController
(Note: This is hypothetical; the bundle may not include this command. Manually scaffold if needed.)
Register Routes
Route::resource('posts', Admin\PostController::class)->middleware('admin');
Extend AdminController
namespace App\Http\Controllers\Admin;
use Brix\AdminBundle\Controller\AdminController;
use App\Models\Post;
class PostController extends AdminController
{
protected $model = Post::class;
protected $title = 'Posts';
public function index()
{
$posts = $this->model::all();
return $this->render('admin/posts/index', compact('posts'));
}
}
Create Views
resources/views/admin/posts/index.blade.phpresources/views/admin/posts/create.blade.phpresources/views/admin/posts/edit.blade.phpAdmin Layout Inheritance
Extend the base admin layout (admin::layout) in your views:
@extends('admin::layout')
@section('sidebar')
@include('admin::partials/sidebar')
@endsection
Middleware Integration
Protect admin routes with middleware (e.g., auth.admin):
Route::middleware(['auth', 'admin'])->group(function () {
Route::resource('posts', Admin\PostController::class);
});
Dynamic Menus
Use the admin_menu helper to generate navigation:
public function index()
{
$menu = [
['route' => 'admin.posts.index', 'label' => 'Posts'],
['route' => 'admin.pages.index', 'label' => 'Pages'],
];
return $this->render('admin/dashboard', compact('menu'));
}
Form Handling Leverage the bundle’s form helpers (if available) for consistency:
{!! Form::open(['route' => 'admin.posts.store']) !!}
{!! Form::text('title', null, ['class' => 'form-control']) !!}
{!! Form::textarea('content', null, ['class' => 'form-control']) !!}
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
{!! Form::close !!}
Asset Management Use the published assets (CSS/JS) or override them:
@push('admin_styles')
<link href="{{ asset('css/admin/custom.css') }}" rel="stylesheet">
@endpush
Authentication
Integrate with Laravel’s auth system (e.g., auth:admin middleware):
// app/Http/Middleware/AdminMiddleware.php
public function handle($request, Closure $next)
{
if (!auth()->user()->isAdmin()) {
abort(403);
}
return $next($request);
}
Permissions
Use a package like spatie/laravel-permission to gate admin features:
public function index()
{
$this->authorize('view', Post::class);
// ...
}
Localization
Override translations in resources/lang/vendor/admin:
// resources/lang/vendor/admin/en/messages.json
{
"dashboard": "Admin Dashboard"
}
API Integration Use the admin bundle for backend management while serving APIs via Laravel’s built-in routes:
Route::prefix('api')->group(function () {
Route::resource('posts', PostController::class)->only(['index', 'store']);
});
Event Listeners Listen for admin events (if the bundle emits them):
// EventServiceProvider
protected $listen = [
'brix.admin.created' => [
AdminCreatedListener::class,
],
];
Asset Conflicts
admin::layout file and customize the asset paths:
@push('admin_styles')
<!-- Your custom styles -->
@endpush
Route Caching
php artisan route:clear or use php artisan route:list to debug.Middleware Order
app/Http/Kernel.php:
protected $routeMiddleware = [
'admin' => \App\Http\Middleware\AdminMiddleware::class,
];
Blade Template Overrides
@extends('admin::layout') explicitly.Database Migrations
users with is_admin flag).Route Debugging
Use php artisan route:list to verify admin routes are registered.
View Debugging Check if views are being loaded from the correct path:
// Temporarily add this to a controller to debug view paths
dd(view()->getFinder()->find('admin/dashboard'));
Middleware Debugging Add logging to middleware to verify execution:
public function handle($request, Closure $next)
{
\Log::info('Admin middleware triggered');
return $next($request);
}
Asset Debugging Clear cached assets:
php artisan view:clear
php artisan cache:clear
Custom Admin Dashboard
Create a dedicated DashboardController to aggregate admin links:
public function index()
{
$stats = [
'posts' => Post::count(),
'pages' => Page::count(),
];
return $this->render('admin/dashboard', compact('stats'));
}
Bulk Actions Implement bulk delete/update in list views:
{!! Form::open(['method' => 'POST', 'action' => ['Admin\PostController@bulkDelete']]) !!}
{!! Form::select('ids[]', $postOptions, null, ['multiple' => true]) !!}
{!! Form::submit('Delete Selected') !!}
{!! Form::close !!}
Soft Deletes Enable soft deletes for models managed in the admin:
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}
Audit Logs
Integrate with spatie/laravel-audit-log to track admin actions:
use Spatie\AuditLog\AuditLog;
public function update(Request $request, $id)
{
$post = Post::findOrFail($id);
$original = $post->
How can I help you explore Laravel packages today?