Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Admin Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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
    
  2. 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']);
    });
    
  3. 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']);
    
  4. 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
    

First Use Case: CRUD for a Model

  1. 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.)

  2. Register Routes

    Route::resource('posts', Admin\PostController::class)->middleware('admin');
    
  3. 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'));
        }
    }
    
  4. Create Views

    • resources/views/admin/posts/index.blade.php
    • resources/views/admin/posts/create.blade.php
    • resources/views/admin/posts/edit.blade.php

Implementation Patterns

Workflows

  1. Admin Layout Inheritance Extend the base admin layout (admin::layout) in your views:

    @extends('admin::layout')
    @section('sidebar')
        @include('admin::partials/sidebar')
    @endsection
    
  2. Middleware Integration Protect admin routes with middleware (e.g., auth.admin):

    Route::middleware(['auth', 'admin'])->group(function () {
        Route::resource('posts', Admin\PostController::class);
    });
    
  3. 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'));
    }
    
  4. 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 !!}
    
  5. Asset Management Use the published assets (CSS/JS) or override them:

    @push('admin_styles')
        <link href="{{ asset('css/admin/custom.css') }}" rel="stylesheet">
    @endpush
    

Integration Tips

  1. 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);
    }
    
  2. Permissions Use a package like spatie/laravel-permission to gate admin features:

    public function index()
    {
        $this->authorize('view', Post::class);
        // ...
    }
    
  3. Localization Override translations in resources/lang/vendor/admin:

    // resources/lang/vendor/admin/en/messages.json
    {
        "dashboard": "Admin Dashboard"
    }
    
  4. 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']);
    });
    
  5. Event Listeners Listen for admin events (if the bundle emits them):

    // EventServiceProvider
    protected $listen = [
        'brix.admin.created' => [
            AdminCreatedListener::class,
        ],
    ];
    

Gotchas and Tips

Pitfalls

  1. Asset Conflicts

    • Issue: Published assets may conflict with your app’s CSS/JS.
    • Fix: Override the admin::layout file and customize the asset paths:
      @push('admin_styles')
          <!-- Your custom styles -->
      @endpush
      
  2. Route Caching

    • Issue: Forgetting to clear route cache after adding admin routes.
    • Fix: Run php artisan route:clear or use php artisan route:list to debug.
  3. Middleware Order

    • Issue: Admin middleware may not load if not registered in app/Http/Kernel.php:
      protected $routeMiddleware = [
          'admin' => \App\Http\Middleware\AdminMiddleware::class,
      ];
      
  4. Blade Template Overrides

    • Issue: Custom views not overriding bundle templates.
    • Fix: Ensure your view paths take precedence. Use @extends('admin::layout') explicitly.
  5. Database Migrations

    • Issue: Admin-specific migrations may not be included.
    • Fix: Manually create migrations for admin tables (e.g., users with is_admin flag).

Debugging

  1. Route Debugging Use php artisan route:list to verify admin routes are registered.

  2. 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'));
    
  3. Middleware Debugging Add logging to middleware to verify execution:

    public function handle($request, Closure $next)
    {
        \Log::info('Admin middleware triggered');
        return $next($request);
    }
    
  4. Asset Debugging Clear cached assets:

    php artisan view:clear
    php artisan cache:clear
    

Tips

  1. 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'));
    }
    
  2. 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 !!}
    
  3. 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'];
    }
    
  4. 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->
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi