Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

towhid's avatar

i want to create two types user panel for two types user.

i want to create two types login user, one is admin and others is customer , what i will do for this scenario .

am i use laravel buitin auth ? or make manualy auth ?

please suggest me - for customize data type table -

0 likes
18 replies
towhid's avatar

@PATROSMANIA - i don't want to use any kind of third party package , i just want to create customize All of things

patrickadvance's avatar

@towhid @patrosmania just add a 'role' column in your users table. Then add a method called isUserAdmin() in your User model like so.


public function isUserAdmin($user){
    if($user->role=='admin'){
        return true;
    }
    
    return false;
}

jlrdw's avatar

You do realize the out of the box form can be duplicated and use one for admins and one for uses.

Of course just have different links setup for admins versus users.

And then the home controller of course have a separate method perhaps for uses.

Many ways to achieve this with all of the out-of-the-box stuff that Taylor provides.

And as said above I just created a role field in my uses table where I have a comma separated list of roles.

towhid's avatar

@JLRDW - suggest me any practical code or video - i don't underrated what i will do for this type of action .thank you

hupp's avatar

First add level column in your main user table after adding just make middleware by using below php artisan make:middleware CheckLevel and put below code in your created middlewere

     /**
     * Handle an incoming request to check is it administrator or not.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $level1, $level2 = null, $level3 = null)
    {
        if (Auth::user() &&  Auth::user()->level == $level1) {
            return $next($request);
        } elseif(Auth::user() && $level2 != null && Auth::user()->level == $level2) {
            return $next($request);
        } elseif(Auth::user() && $level3 != null && Auth::user()->level == $level3) {
            return $next($request);
        } else {
            return response()->view('accessDenied.404');
        }
    }

Now changes your route file according to role like below

Route::group(['middleware' => ['CheckLevel:level1']], function() {
    /****Level1 Route****/
    Route::get('level1','Controller@index');        
});
Route::group(['middleware' => ['CheckLevel:level2']], function() {
    /****Level2 Route****/
    Route::get('level2','Controller@index');        
});
Route::group(['middleware' => ['CheckLevel:level1,level2']], function() {
    /****Level1and level2 mix Route****/
    Route::get('level1/level2','Controller@index');     
});

No need change code in your existing project just follow above step. Hope this is work for you

jlrdw's avatar
jlrdw
Best Answer
Level 75

Duplicate this:

Use and design one for admin the other for customers.

Not hard at all. You can add links as needed to top nav.

See in example, I added a link to pets.

towhid's avatar

@JLRDW - i think i cannot make you understand :/

for this thing i want learn many ways in laracasts -

if i have -- two or three or multi types user access then they have difference data field for difference user type , so how to access check or login panel , i want to use one login panel is this possible ? or need multi login panel ? for multi user type ? i just want t clear ... thank you

jlrdw's avatar

At one place you say:

i want to use one login panel is this possible

Another place:

i want to create two types user panel for two types user.

Which is what was explained and asked. Now you changed your mind.

This makes it hard to help you.

Yes then just have one login panel. Or two, however many you need. It's just a form.

The buttons are the key, determines if admin or customer. Me, I would have separate forms for admin vs customer, but you do as you think you need to.

See pets above, it's in the routes and policies where you determine what a user can and cannot do.

One user can view, not edit. Another user can edit, etc. You have to write in the RBAC (gates and policies).

Also a user can see and edit their own data.

towhid's avatar

@JLRDW - sorry if i mistakenly not make you understand , but as my need i check in google there are many type of solution like - auth.php file changes or add some driver i also try but not exactly what i was want . even i don't understand why this procedure use here . why this need ? and when its need ? [ just confuse]

authorization and authentication is my week point in laravel that's why you suggest me two chapter if i want know out of box --- r8 ? but i cannot understand and not even clear from documentation i want practically code support - that's why i am still searching - the answer .

i know default auth -- use how to use in middle ware related issue , which one edit , which one delete which one access but i don't understand if i have multi user access system one is client end and another is admin == then how to go my scenario . am i go default auth system or am i go multi table support in single panel , even i don't now is it possible or not :/

jlrdw's avatar

In this series: https://laracasts.com/series/laravel-from-scratch-2018

Jeffrey covers basic Authentication and Authorization.

Also google search this:

site:laracasts.com Authentication and Authorization

The main thing to remember is:

A user either CAN OR CANNOT do something. So just look at your routes, controllers, and models with that in mind.

And a scope could be used where an admin sees all, but user only sees their data using auth->id.

towhid's avatar

@PHPHUPPTECHNOLOGIES - after following your instruction use this existing user's migrations table

$table->string('level',255)->nullable();

then migrate and use make:auth command, then create middle ware use this code

public function handle($request, Closure $next, $level1, $level2 = null, $level3 = null)
    {
        if (Auth::user() &&  Auth::user()->level == $level1) {
            return $next($request);
        } elseif(Auth::user() && $level2 != null && Auth::user()->level == $level2) {
            return $next($request);
        } elseif(Auth::user() && $level3 != null && Auth::user()->level == $level3) {
            return $next($request);
        } else {
            return response()->view('accessDenied.404');
        }
    }

and use this code fro route

Route::group(['middleware' => ['CheckLevel:level1']], function() {
    /****Level1 Route****/
    Route::get('level1','Controller@index');        
});
Route::group(['middleware' => ['CheckLevel:level2']], function() {
    /****Level2 Route****/
    Route::get('level2','Controller@index');        
});
Route::group(['middleware' => ['CheckLevel:level1,level2']], function() {
    /****Level1and level2 mix Route****/
    Route::get('level1/level2','Controller@index');     
});

out put is default nothing change after add al of your instruction i think this is not accurate way because of you didnot share proper step , if you don't mind please write proper way till login panel and admin panel show

jlrdw's avatar

Just remember, you will have to code in the logic, routes, etc. As example in app.blade.php I had to add:

<a class="navbar-brand" href="{{ url('pet/index') }}">Pets</a>

So my point was you can duplicate

app.blade.php
and
home.blade.php

Name them whatever and have one "home page" for admins, yet another for "customers". While still using laravel Authentication and Authorization.

I just like the design Taylor used.

Note, you can have the one for admin only load if Authenticated and Authorized.

felipepena's avatar

@towhid I think the package I just shared can give you ideas of how to implement it on your own. It's a very simple package.

Please or to participate in this conversation.