Implement authorization to determine who can and cannot do something.
A route group is correct, to ensure login is required.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I created a separate admin route file, admin.php in routes folder with the following content
<?php
use App\Http\Livewire\Admin\Index;
use Illuminate\Support\Facades\Route;
Route::get('/', Index::class)->name('admin');
and added the following in RouteServiceProvider
Route::prefix('admin')
->middleware(['web', 'auth:sanctum', 'verified', 'admin'])
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
where the admins are verified using a middleware. This seems working and I wish to know this is enough to protect from non-admins reaching the admin route file. Or should I need to use something like the Route::group?
In your first example notice the group() method. Either way is creating a route group and in both examples you are applying the admin middleware. So as long as the admin middleware correctly blocks requests from non-admins either way is fine it just becomes a question of which way to you prefer, a dedicated route file or keep everything in web.php
Please or to participate in this conversation.