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

Laravel Admin Laravel Package

geeklearners/laravel-admin

Laravel package for building an admin panel in your Laravel app, offering basic scaffolding for admin routes, views, and UI components to manage application data from a backend interface.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require geeklearners/laravel-admin
    php artisan vendor:publish --provider="Geeklearners\Admin\AdminServiceProvider"
    php artisan migrate
    
    • Publishes config (config/admin.php) and migrations (creates admins table).
  2. First Admin User

    php artisan admin:create --name="Admin User" --email="admin@example.com" --password="securepassword"
    
    • Creates a super-admin with default permissions.
  3. Basic Usage

    • Access the admin panel at /admin (configured in config/admin.php).
    • Log in with the credentials created above.
  4. Key Configurations

    • Update config/admin.php to customize:
      • admin_path (default: /admin)
      • guard (default: admin)
      • middleware (e.g., auth:admin)

First Use Case: CRUD for a Model

  1. Generate a CRUD Controller

    php artisan admin:make:controller Post --model=Post
    
    • Creates a controller with index, create, store, edit, update, destroy methods.
  2. Register the Route Add to routes/admin.php:

    Route::resource('posts', \App\Http\Controllers\Admin\PostController::class);
    
  3. Access the Panel

    • Navigate to /admin/posts to see the auto-generated CRUD interface.

Implementation Patterns

1. Model-Based CRUD

  • Auto-Generated Controllers The package generates controllers with pre-built CRUD logic for Eloquent models.

    • Customize by overriding methods in the generated controller (e.g., index(), store()).
  • Form Fields Define fields in the model or controller using fluent syntax:

    public function fields()
    {
        return [
            'id',
            'title' => 'Title',
            'content' => 'Content',
            'published_at' => 'Published At|datetime',
        ];
    }
    

2. Customization via Traits

  • Extend functionality with traits:
    use Geeklearners\Admin\Traits\HasBulkActions;
    use Geeklearners\Admin\Traits\HasExport;
    
    • Bulk Actions: Add deleteSelected() to enable bulk delete.
    • Export: Add export() to enable CSV/Excel export.

3. Role-Based Permissions

  • Assign roles to admins via middleware:
    // routes/admin.php
    Route::resource('posts', PostController::class)->middleware('can:manage,posts');
    
  • Define permissions in config/admin.php:
    'permissions' => [
        'manage' => ['posts', 'users'],
    ],
    

4. Integration with Existing Auth

  • Use the admin guard alongside Laravel’s default web guard:
    // config/auth.php
    'guards' => [
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],
    

5. Theming and Assets

  • Override default views by publishing assets:
    php artisan vendor:publish --tag=admin-assets
    
  • Customize the admin panel’s resources/views/admin/ directory.

Gotchas and Tips

Pitfalls

  1. Migration Conflicts

    • The admins table migration may conflict with existing migrations. Run:
      php artisan migrate --path=vendor/geeklearners/laravel-admin/database/migrations
      
      before your app’s migrations.
  2. Route Caching

    • Clear routes after adding new admin routes:
      php artisan route:clear
      
  3. Permission Denied

    • Ensure the admin guard is properly configured in config/auth.php.
    • Verify the user has the correct role/permission in the database.
  4. CSRF Token Mismatch

    • If using the admin panel in an API-like context, ensure CSRF middleware is excluded for admin routes:
      Route::middleware(['web', 'admin'])->group(function () { ... });
      

Debugging Tips

  1. Log Admin Activity

    • Enable logging in config/admin.php:
      'log_activity' => true,
      
    • Check logs at storage/logs/laravel-admin.log.
  2. Dump Generated SQL

    • Add DB::enableQueryLog() in your controller to inspect queries:
      public function index()
      {
          DB::enableQueryLog();
          $posts = Post::all();
          dd(DB::getQueryLog());
      }
      
  3. Override Default Views

    • Copy the package’s views to resources/views/vendor/admin/ to customize without modifying the package directly.

Extension Points

  1. Custom Fields

    • Extend the field system by creating a custom field type:
      namespace App\Admin\Fields;
      
      use Geeklearners\Admin\Fields\Field;
      
      class CustomField extends Field
      {
          public function render()
          {
              return '<input type="text" name="custom_field">';
          }
      }
      
    • Register in config/admin.php:
      'fields' => [
          'custom' => \App\Admin\Fields\CustomField::class,
      ],
      
  2. Event Listeners

    • Listen to admin events (e.g., admin.user.created):
      // EventServiceProvider
      protected $listen = [
          'admin.user.created' => [
              \App\Listeners\LogAdminCreation::class,
          ],
      ];
      
  3. API Endpoints

    • The package is not API-first, but you can expose admin functionality via API by creating separate controllers:
      Route::prefix('api/admin')->middleware('auth:admin')->group(function () {
          Route::get('posts', [PostController::class, 'apiIndex']);
      });
      
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky