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

LearnWithMoin's avatar

How to create custom guard login and register in laravel livewire?

I am developing an e-commerce website. Currently, I am using Laravel Livewire for this project. I need multiple guard logins like Seller, Customer, and Admin. How can I create a custom guard in Laravel Livewire?

0 likes
10 replies
tykus's avatar

I need multiple guard logins like Seller, Customer, and Admin

Do you really need custom guards; or do you need to implement Authorization correctly?

LearnWithMoin's avatar

@tykus Yes! I need a custom guard authentication. Because I am developing separate dashboards for users, sellers and admins.

tykus's avatar

@LearnWithMoin no, you do not. Separate dashboards / pages can be achieved using Role Based Access Control (RBAC)

tykus's avatar

@LearnWithMoin do you really? You can have different login views that all POST to the same endpoint and handle post-login redirection based on the authenticated user's role?

Anyway, you have been told from the outset by myself and @martinbean that custom guards are not needed to achieve what you need, but you choose not to heed the advice, so good luck with your project.

JussiMannisto's avatar

@LearnWithMoin You don't need multiple guards. You can create gates for authorization. For example:

Gate::define('admin', function(User $user) {
	return $user->role === 'admin';
});

You can then use them as middleware:

Route::middleware('can:admin')->group(function() {
	Route::post('/admin/do-stuff/', [AdminController::class, 'doStuff']);
	Route::post('/admin/other-stuff/', [AdminController::class, 'otherStuff']);
});

Or you can use them in code:

if($request->user()->can('admin')) {
	...
}
martinbean's avatar

I need multiple custom guards for a separate dashboard

@LearnWithMoin No, you don’t. You just need to use authorisation to determine what routes a user can and cannot access based on their role(s).

Route::middleware('auth')->group(function () {
    Route::middleware('role:seller')->group(function () {
        // Seller-only routes...
    });

    Route::middleware('role:admin')->group(function () {
        // Admin-only routes...
    });
});
Snapey's avatar

dont do it. Everyone shoukd be authenticated using the same mechanism. You can then use whatever method you like to decide where to send them and control what they can do.

Please or to participate in this conversation.