Route::middleware(['auth', 'role:admin'])->name('admin.')->prefix('admin')->group(function(){
Route::get('/role', [RoleController::class, 'index'])->name('index');
});
I want to user this route name. How I can?
<li class="nav-item">
<a href="{{ url('admin/role') }}" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Roles</p>
</a>
</li>
user as url and it’s working but I want to user the route name
3
Answers
Instead of
url()
method ,useroute()
.Hereadmin
refers to->name('admin.')
andindex
refers to->name('index')
Ref: URLs For Named Routes
route method parameters
You can use route() function to get url based on its name. Keep in mind that the prefix wont change the name defined in route, so in your case the name will be "index", not "admin.index"
But it will be better if you use a more detailed route name to prevent overlapped of route name, Example :
so you will be able to call them with this :
Route::resource(‘routename’, ExampleController::class);
});