{"id":869,"date":"2022-08-23T11:52:09","date_gmt":"2022-08-23T11:52:09","guid":{"rendered":"https:\/\/appfinz.com\/blogs\/?p=869"},"modified":"2026-01-18T12:52:21","modified_gmt":"2026-01-18T12:52:21","slug":"laravel-middleware-for-auth-admin-users-roles","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/laravel-middleware-for-auth-admin-users-roles\/","title":{"rendered":"Laravel Admin Middleware for Auth Admin Users Roles [Laravel 12, Updated 2026]"},"content":{"rendered":"\n<p>In this post, we will see <strong>How to make Admin panel working in Laravel 12 | Admin Middleware in Laravel Working<\/strong><\/p>\n\n\n\n<p>Examples of <strong>Laravel Middleware for Auth Admin Users Roles<\/strong>. This tutorial shows how to build a sample Laravel middleware for the admin role from scratch. Check if the authenticated user is an admin or a user. If he&#8217;s a user, he can&#8217;t get admin access to&nbsp;get&nbsp;admin pages.<\/p>\n\n\n\n<p>Middleware provides a convenient mechanism for filtering incoming HTTP requests to your application. Laravel provides authentication middleware that validates that users of your application have been authenticated. Here we use an admin middleware where the user is not an admin and the middleware redirects the user to the dashboard. <\/p>\n\n\n\n<p>However, if the user is an administrator, the middleware allows the request to proceed further to the application. This tutorial will show you step by step how to use middleware in Laravel, or how to call middleware in your controller. Let&#8217;s start with the single-role or multi-role Laravel middleware admin&nbsp;role<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Laravel 12 Middleware Example Tutorial [Updated Laravel 12]<\/strong><\/h2>\n\n\n\n<p>Follow the following steps to create Laravel middleware for auth admin and user roles:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Step 1 \u2013 Install Laravel App<\/li>\n\n\n\n<li>Step 2 \u2013 Connect Database to App<\/li>\n\n\n\n<li>Step 3 \u2013 Generate Laravel Authentication<\/li>\n\n\n\n<li>Step 4 \u2013 Update User&#8217;s Migration<\/li>\n\n\n\n<li>Step 5 \u2013 Create Middleware<\/li>\n\n\n\n<li>Step 6 \u2013 Admin Protected Middleware Route<\/li>\n\n\n\n<li>Step 7 \u2013 Create &amp; Update Blade Files<\/li>\n\n\n\n<li>Step 8 \u2013 Update Controller Methods<\/li>\n\n\n\n<li>Step 9 \u2013 Multiple Middlewares in Single Route<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h4 class=\"wp-block-heading\"><strong>Step 1: Install Laravel App<\/strong><\/h4>\n\n\n\n<p>First at all, install Laravel 12 using Composer. Open a new command-line interface and run the following command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Terminal&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer create-project --prefer-dist laravel\/laravel laravel-admin<\/pre><\/div>\n<\/div><\/div>\n\n\n\n<p>Go inside the folder app:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Terminal&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">cd laravel-admin<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Connect Database to App<\/strong><\/h4>\n\n\n\n<p>Now, open your laravel application .env file and make the following database related changes in it.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Blade PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=laravel_admin\nDB_USERNAME=root\nDB_PASSWORD=<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Generate Laravel Authentication<\/strong> Using Latest Laravel UI 4.x for Laravel 9, 10, 11, Here we are using Bootstrap Auth You can also use Vue or React Auth According to your need<\/h4>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Terminal&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer require laravel\/ui\nphp artisan ui bootstrap --auth\n  \nnpm install\nnpm run dev \/\/ Press CTRL + C Then Again hit below mentioned command\nnpm run build<\/pre><\/div>\n\n\n\n<p>Open users table migration and update the is_admin field on it. Here using this is_admin we will filter our Admin user to enter admin routes<\/p>\n\n\n\n<p>database\/migrations\/<strong>0001_01_01_000000_create_users_table.php<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 4: Update User&#8217;s Migration<\/strong><\/h4>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nreturn new class extends Migration\n{\n    \/**\n     * Run the migrations.\n     *\/\n    public function up(): void\n    {\n        Schema::create('users', function (Blueprint $table) {\n            $table-&gt;bigIncrements('id');\n            $table-&gt;string('name');\n            $table-&gt;string('email')-&gt;unique();\n            $table-&gt;timestamp('email_verified_at')-&gt;nullable();\n            $table-&gt;string('password');\n            $table-&gt;boolean('is_admin')-&gt;nullable();\n            $table-&gt;rememberToken();\n            $table-&gt;timestamps();\n        });\n\n        Schema::create('password_reset_tokens', function (Blueprint $table) {\n            $table-&gt;string('email')-&gt;primary();\n            $table-&gt;string('token');\n            $table-&gt;timestamp('created_at')-&gt;nullable();\n        });\n\n        Schema::create('sessions', function (Blueprint $table) {\n            $table-&gt;string('id')-&gt;primary();\n            $table-&gt;foreignId('user_id')-&gt;nullable()-&gt;index();\n            $table-&gt;string('ip_address', 45)-&gt;nullable();\n            $table-&gt;text('user_agent')-&gt;nullable();\n            $table-&gt;longText('payload');\n            $table-&gt;integer('last_activity')-&gt;index();\n        });\n    }\n\n    \/**\n     * Reverse the migrations.\n     *\/\n    public function down(): void\n    {\n        Schema::dropIfExists('users');\n        Schema::dropIfExists('password_reset_tokens');\n        Schema::dropIfExists('sessions');\n    }\n};\n<\/pre><\/div>\n\n\n\n<p>After adding the column now run the migration just running the following command.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Terminal&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">php artisan migrate<\/pre><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h4 class=\"wp-block-heading\"><strong>Step 5: Create Middleware<\/strong><\/h4>\n\n\n\n<p>Now Create middleware for handling auth admin roles. Open the terminal and run below command.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">php artisan make:middleware IsAdmin<\/pre><\/div>\n\n\n\n<p>Now you check you have generated a file in your project middleware directory, open and update the below code on it.<\/p>\n\n\n\n<p><strong>app\\Http\\Middleware\\IsAdmin.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\nuse Auth;\n\nclass IsAdmin\n{\n    \/**\n     * Handle an incoming request.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  \\Closure  $next\n     * @return mixed\n     *\/\n    public function handle($request, Closure $next)\n    {\n        if (Auth::user() &amp;&amp;  Auth::user()-&gt;is_admin == 1) {\n             return $next($request);\n        }\n\n        return redirect('home')-&gt;with('error','You have not admin access');\n      \/\/ It will redirect user back to home screen if they do not have is_admin=1 assigned in database\n    }\n}<\/pre><\/div>\n\n\n\n<p class=\"has-vivid-green-cyan-color has-text-color has-link-color wp-elements-c794967415541eb002c80920dd1b671b\"><strong>In Laravel 12, You can add\/register middleware in bootstrap\/app.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">-&gt;withMiddleware(function (Middleware $middleware) {\n    $middleware-&gt;alias([\n        'admin' =&gt; \\App\\Http\\Middleware\\AdminMiddleware::class,\n    ]);\n})<\/pre><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-link-color wp-elements-99334e796b112aea45de40380f9b1438\"><strong>Below Laravel 12 Application like in 8,9 or 10 laravel version, You can add\/register middleware in app\\Http\\Kernel.php<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>For Laravel 8,9 or 10 open your kernel.php file and go to the protected $routeMiddleware property and update the&nbsp;admin&nbsp;middleware here.<\/strong><\/mark><\/p>\n\n\n\n<p><strong>app\\Http\\Kernel.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">    protected $routeMiddleware = [\n        'throttle' =&gt; \\Illuminate\\Routing\\Middleware\\ThrottleRequests::class,\n        'verified' =&gt; \\Illuminate\\Auth\\Middleware\\EnsureEmailIsVerified::class,\n        'admin' =&gt; \\App\\Http\\Middleware\\IsAdmin::class,\n    ];<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 6: Admin Protected Middleware Route<\/strong><\/h4>\n\n\n\n<p>Create routes that an administrator must protect. If the user is not an admin, they will be redirected to the home page. Otherwise, he can visit this page. Now if I want to assign routes to this middleware admin, these routes will be secured and only accessible if the authorized user is an admin. Otherwise, you will be redirected to the home page.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">php artisan make:controller AdminController<\/pre><\/div>\n\n\n\n<p><strong>app\/routes\/web.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">use Illuminate\\Support\\Facades\\Route;\nuse App\\Http\\Controllers\\HomeController;\n \n Route::get('\/', function () {\n    return view('welcome');\n});\n\nAuth::routes();\n\nRoute::get('\/home', [App\\Http\\Controllers\\HomeController::class, 'index'])-&gt;name('home');\n\nRoute::group(['middleware' =&gt; ['auth', 'admin']], function () {\n    Route::get('admin-home', [App\\Http\\Controllers\\AdminController::class, 'adminHome'])-&gt;name('admin.home');\n});\n\/\/ Here it is checking two middlewares auth and admin, it means if user is authenticated and having admin right (is_admin=1) only in that case they will reach this route\n<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 7: Create &amp; Update Blade Files<\/strong><\/h4>\n\n\n\n<p>Add accessing page link add in the home page which is open after user login.<\/p>\n\n\n\n<p><strong>resources\\views\\home.blade.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">@extends('layouts.app')\n\n@section('content')\n&lt;div class=&quot;container&quot;&gt;\n    &lt;div class=&quot;row justify-content-center&quot;&gt;\n        &lt;div class=&quot;col-md-8&quot;&gt;\n            &lt;div class=&quot;card&quot;&gt;\n                &lt;div class=&quot;card-header&quot;&gt;Dashboard&lt;\/div&gt;\n\n                &lt;div class=&quot;card-body&quot;&gt;\n                    @if (session('error'))\n                    &lt;div class=&quot;alert alert-danger&quot;&gt;\n                      {{ session('error') }}\n                    &lt;\/div&gt;\n                    @endif\n                    @if (session('status'))\n                        &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt;\n                            {{ session('status') }}\n                        &lt;\/div&gt;\n                    @endif\n\n                    You are logged in!\n\n                &lt;\/div&gt;\n                &lt;div class=&quot;card-body&quot;&gt;\n                    &lt;div class=&quot;panel-body&quot;&gt;\n                      Check admin view:\n                      &lt;a href=&quot;{{route('admin.home')}}&quot;&gt;Admin Home&lt;\/a&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n@endsection<\/pre><\/div>\n\n\n\n<p>Create a blade file if the user is authenticated with admin then access this page.<\/p>\n\n\n\n<p><strong>resources\\views\\admin-home.blade.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">@extends('layouts.app')\n\n@section('content')\n&lt;div class=&quot;container&quot;&gt;\n    &lt;div class=&quot;row justify-content-center&quot;&gt;\n        &lt;div class=&quot;col-md-8&quot;&gt;\n            &lt;div class=&quot;card&quot;&gt;\n                &lt;div class=&quot;card-header&quot;&gt;Admin Home&lt;\/div&gt;\n\n                &lt;div class=&quot;card-body&quot;&gt;\n                  Welcome to admin dashboard\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n@endsection<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 8: Update Controller Methods<\/strong><\/h4>\n\n\n\n<p>Now add a method in your controller if a user is authenticated with admin then admin-home function work.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;Laravel&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\n\nclass HomeController extends Controller\n{\n    \/**\n     * Create a new controller instance.\n     *\n     * @return void\n     *\/\n    public function __construct()\n    {\n        $this-&gt;middleware('auth');\n    }\n\n    \/**\n     * Show the application dashboard.\n     *\n     * @return \\Illuminate\\Contracts\\Support\\Renderable\n     *\/\n    public function index()\n    {\n        return view('home');\n    }\n\n    public function adminHome()\n    {\n        return view('admin-home');\n    }\n}<\/pre><\/div>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Register Middleware in <code>bootstrap\/app.php<\/code><\/mark><\/strong><\/p>\n\n\n\n<p>In Laravel 12, you <strong>register custom middleware here<\/strong>. Add under the middleware section:<\/p>\n\n\n\n<p>Open: <code>bootstrap\/app.php<\/code><\/p>\n\n\n\n<p><strong>\u2705 How to Properly Register Your <code>IsAdmin<\/code> Middleware in Laravel 12<\/strong> <strong>[Updated]<\/strong><\/p>\n\n\n\n<p>So the relevant part of <code>bootstrap\/app.php<\/code> looks like:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">    -&gt;withMiddleware(function (Middleware $middleware) {\n        $middleware-&gt;alias([\n            'admin' =&gt; \\App\\Http\\Middleware\\IsAdmin::class,\n        ]);\n    })<\/pre><\/div>\n\n\n\n<p>In your laravel Application put your user table value to is_admin value to 1 for changing default user to admin access like i did open your phpmyadmin and update 1<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"262\" src=\"https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2022\/08\/WhatsApp-Image-2024-08-28-at-15.29.01-1024x262.jpeg\" alt=\"\" class=\"wp-image-1304\" title=\"\" srcset=\"https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2022\/08\/WhatsApp-Image-2024-08-28-at-15.29.01-1024x262.jpeg 1024w, https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2022\/08\/WhatsApp-Image-2024-08-28-at-15.29.01-300x77.jpeg 300w, https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2022\/08\/WhatsApp-Image-2024-08-28-at-15.29.01-768x197.jpeg 768w, https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2022\/08\/WhatsApp-Image-2024-08-28-at-15.29.01.jpeg 1350w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>And now if you are accessing <\/p>\n\n\n\n<p><a href=\"http:\/\/localhost\/wd\/admin\/home\">http:\/\/localhost\/laravel-admin\/admin\/home<\/a><\/p>\n\n\n\n<p>Then you ll see that laravel Admin can be accessible via this url<\/p>\n\n\n\n<p>Note: User must be registered and updated is_admin=1 is database, you can manually update it also, you can also specify different. admin routes and admin directories also.<\/p>\n\n\n\n<p>Thanks for now, if you have any types of queries, do message me once, i ll try to help you. Happy Coding<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel Admin Pannel Setup, Laravel Middleware Updated Laravel 11<\/p>\n","protected":false},"author":1,"featured_media":877,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,21],"tags":[213,215,216,214,212],"class_list":["post-869","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-laravel","tag-admin-middleware","tag-admin-pannel-in-laravel","tag-laravel-admin-pannel-creation","tag-make-admin-pannel-in-laravel","tag-middleware"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=869"}],"version-history":[{"count":15,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/869\/revisions"}],"predecessor-version":[{"id":1511,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/869\/revisions\/1511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/877"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}