Creating an admin panel in Laravel allows you to manage your application’s data and users through a secure backend interface.
Start by setting up authentication using Laravel Breeze, Jetstream, or Laravel UI.
Use middleware to restrict access so only admin users can access admin routes.
Create controllers, routes, and Blade views to build the admin dashboard.
You can extend it with CRUD operations, charts, roles, and file management features.
Install Laravel (Skip if already installed)
Put this comment in your project terminal:
composer create-project laravel/laravel laravel-admin-panel
cd laravel-admin-panel
Set Up Authentication
Install Laravel Breeze, Jetstream, or Laravel UI for authentication. For simplicity, let’s use Laravel Breeze:
Put this comment in your project terminal:
composer require laravel/breeze --dev
php artisan breeze:install
npm install && npm run dev
php artisan migrate
This gives you login, register, forgot password, etc.
Create Middleware for Admin
Generate middleware:
Put this comment in your project terminal:
php artisan make:middleware IsAdmin
Then edit app/Http/Middleware/IsAdmin.php
:
public function handle($request, Closure $next)
{
if (auth()->check() && auth()->user()->is_admin) {
return $next($request);
}
abort(403, 'Unauthorized');
}
Register the middleware:
app/Http/Kernel.php
// app/Http/Kernel.php
protected $routeMiddleware = [
// ...
'is_admin' => \App\Http\Middleware\IsAdmin::class,
];
Add is_admin
Column to Users Table
Update migration:
database/migrations/xxxx_xx_xx_create_users_table.php
// database/migrations/xxxx_xx_xx_create_users_table.php
$table->boolean('is_admin')->default(false);
Then migrate:
Put this comment in your project terminal:
php artisan migrate
Make a user admin manually:
Put this comment in your project terminal:
php artisan tinker
>>> \App\Models\User::find(1)->update(['is_admin' => true]);
Create Admin Routes and Controller
Edit routes/web.php
:
Route::middleware(['auth', 'is_admin'])->group(function () {
Route::get('/admin', [App\Http\Controllers\Admin\AdminController::class, 'index'])->name('admin.dashboard');
});
Create controller:
Put this comment in your project terminal:
php artisan make:controller Admin/AdminController
Then define the method:
app/Http/Controllers/Admin/AdminController.php
// app/Http/Controllers/Admin/AdminController.php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function index()
{
return view('admin.dashboard');
}
}
Create Blade View for Admin Dashboard
mkdir resources/views/admin
touch resources/views/admin/dashboard.blade.php
Add simple HTML:
resources/views/admin/dashboard.blade.php
@extends('layouts.app')
@section('content')
<h1>Admin Dashboard</h1> Welcome, {{ auth()->user()->name }}!
@endsection
Redirect Admins to Admin Panel (Optional)
Edit app/Providers/RouteServiceProvider.php
:
public const HOME = '/dashboard'; // Change this if needed
Or update login logic to redirect admins:
// in LoginController or after login
if (auth()->user()->is_admin) {
return redirect('/admin');
} else {
return redirect('/dashboard');
}