Build a Laravel Admin Panel in 10 Minutes: A Practical Guide

18 views 0 likes 0 comments 18 minutesOriginalTutorial

Skip boilerplate and generate production-ready CRUD interfaces in Laravel in just 10 minutes. This step-by-step guide covers installation, a real-world product management example, and essential troubleshooting tips for backend developers.

#Laravel # laravel-admin # Admin Panel # CRUD # PHP Tutorial # Rapid Development
Build a Laravel Admin Panel in 10 Minutes: A Practical Guide

Why You Need an Admin Panel Generator

As a backend developer, I face the same challenge with almost every new project: before the core business logic is even finished, the product manager or boss asks for an admin panel—user management, content moderation, data analytics, role-based access... the list goes on.

Building one from scratch is painful. You have to write controllers, configure routes, design Blade templates, implement pagination, validate forms, and handle CRUD operations across multiple modules. Two days vanish, and each module ends up with inconsistent UI.

That’s when I discovered laravel-admin. With over 11,000 GitHub stars, this open-source package promises a "fully functional admin panel in 10 minutes." After testing it, it delivers. Built on the Laravel ecosystem, it automatically generates paginated, searchable, exportable, and permission-controlled CRUD interfaces based on your database models—no frontend coding required.

In this tutorial, I’ll walk you through building a Product Management Backend from scratch. By the end, you’ll have a production-ready system you can deploy immediately. Let’s dive in.

Prerequisites

Before starting, ensure your environment meets these requirements:

  • PHP >= 7.0 (PHP 8.x recommended for better performance)
  • Laravel 5.5+ (Laravel 10/11 recommended)
  • Fileinfo PHP Extension (usually enabled by default)
  • Composer and MySQL/SQLite installed

If you don’t have a Laravel project yet, create one:

bash 复制代码
composer create-project --prefer-dist laravel/laravel admin-demo
cd admin-demo

Make sure your .env database configuration is correctly set up, as laravel-admin will create its own authentication and permission tables.

Quick Start: 3-Step Installation

Step 1: Install Dependencies

Run the following command in your project directory:

bash 复制代码
composer require encore/laravel-admin

This pulls in the package and its dependencies. It wraps the classic AdminLTE template into Laravel-friendly abstractions, allowing you to define admin pages using pure PHP.

Step 2: Publish Assets & Config

bash 复制代码
php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"

After running this, you’ll find config/admin.php in your root directory. This is your central configuration file for changing the installation directory (default: admin), database connection, site title, and more. Defaults work fine for getting started.

Step 3: Run Database Migrations

bash 复制代码
php artisan admin:install

This command does two things:

  1. Creates 5 required tables in your database (admin_users, admin_roles, admin_permissions, etc.)
  2. Seeds a default super admin account. Both username and password are admin.

Visit http://localhost:8000/admin/ and log in with admin/admin. You’ll be greeted by a clean dashboard.

Why 3 steps? This follows Laravel’s standard package installation pattern: install PHP dependencies → publish configs/assets to the project → run database migrations. Mastering this pattern will save you hours when working with any Laravel third-party package.

Practical Example: Building a Product Management Backend

An empty shell isn’t useful. Let’s tackle a real-world scenario: Product Management, including CRUD operations, filtering, and image uploads.

1. Create Database Table & Model

bash 复制代码
php artisan make:model Product -m

The -m flag generates a migration file. Open database/migrations/xxx_create_products_table.php and define your schema:

php 复制代码
public function up()
{
    Schema::create('products', function (Blueprint $table) {
        $table->id();
        $table->string('name', 100)->comment('Product name');
        $table->decimal('price', 10, 2)->default(0)->comment('Price');
        $table->integer('stock')->default(0)->comment('Stock quantity');
        $table->tinyInteger('status')->default(1)->comment('Status: 1=Active, 0=Inactive');
        $table->string('image')->nullable()->comment('Product image URL');
        $table->timestamps();
    });
}

Run the migration:

bash 复制代码
php artisan migrate

2. Generate Admin Controller

bash 复制代码
php artisan admin:make ProductController --model=App\\Models\\Product

This is the package’s killer feature. It auto-generates a controller skeleton based on your Eloquent model. Open app/Admin/Controllers/ProductController.php. The core logic looks like this:

php 复制代码
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ProductController extends Controller
{
    public function grid()
    {
        $grid = new Grid(new Product());

        $grid->column('id', 'ID')->sortable();
        $grid->column('name', 'Product Name');
        $grid->column('price', 'Price')->sortable();
        $grid->column('stock', 'Stock');
        $grid->column('status', 'Status')->using([0 => 'Inactive', 1 => 'Active'])->label([
            0 => 'danger', 1 => 'success'
        ]);
        $grid->column('image', 'Image')->image('', 50, 50);
        $grid->column('created_at', 'Created At')->sortable();

        return $grid;
    }

    protected function form()
    {
        $form = new Form(new Product());

        $form->text('name', 'Product Name')->rules('required|max:100');
        $form->decimal('price', 'Price')->default(0);
        $form->number('stock', 'Stock')->default(0);
        $form->switch('status', 'Status')->default(1);
        $form->image('image', 'Product Image');

        return $form;
    }
}

The API is highly intuitive: grid() defines the list view columns, while form() defines the create/edit form fields. You don’t need to write a single line of HTML or JS. laravel-admin renders beautiful tables and forms automatically.

3. Register Routes

Open app/Admin/routes.php and add:

php 复制代码
$router->resource('products', ProductController::class);

Log into the admin panel → Click Admin in the sidebar → Menu → Create New:

  • Title: Product Management
  • URI: /products
  • Icon: e.g., fa-shopping-cart

Save, refresh, and your new menu item will appear. Click it to manage your products instantly.

Troubleshooting & Pro Tips

Q1: Getting a 500 error on /admin?
Check folder permissions for storage and bootstrap/cache:

bash 复制代码
chmod -R 775 storage bootstrap/cache

Also, verify that route.prefix in config/admin.php matches your actual URL.

Q2: Image upload fails with "disk not configured"?
laravel-admin relies on Laravel’s filesystem. Ensure .env has FILESYSTEM_DISK=public (or AWS_S3 depending on your setup) and run php artisan storage:link to create the symbolic link.

Q3: Garbled text or encoding issues?
Your database and tables must use utf8mb4. Create your DB with:

sql 复制代码
CREATE DATABASE demo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Q4: Composer dependency conflicts on PHP 8.2+?
Older versions of the package may lack full compatibility with newer PHP versions. If Composer fails, pin a stable version:

bash 复制代码
composer require encore/laravel-admin:"^1.8"

Q5: Slow performance with many form fields?
Use grid->paginate(20) to limit rows per page, or add database indexes to frequently queried columns.

Summary & Next Steps

Let’s recap our workflow:

  1. Install (3 commands) → 2. Schema + Model → 3. Generate Controller (1 command) → 4. Route + MenuProduction Ready

The real power of laravel-admin lies in abstracting the repetitive, boilerplate-heavy parts of backend development (lists, pagination, search, forms, permissions) into a configuration-driven API. This lets you focus purely on business logic. Whether you’re shipping fast, building internal tools, or onboarding junior developers, it’s a massive productivity booster.

Where to go next:

  • Role-Based Access Control (RBAC): Create roles like Operator, Reviewer, Admin, and apply row-level or menu-level permissions.
  • Extensions: Official plugins for media management, task scheduling, Redis monitoring, and rich text editors.
  • Custom Dashboards: Use Content, Row, and Column components to build analytics boards.
  • API-First Backend: Pair with Laravel Sanctum to decouple the frontend and backend.

With 11k+ stars, laravel-admin has proven its worth. If you’re tired of being told "just spin up another admin panel", give this approach a try. Drop your questions in the comments—I’ll reply as soon as I can.

Last Updated:2026-07-03 10:10:10

Comments (0)

Post Comment

Loading...
0/500
Loading comments...