Consider these line in routes/web.php
Route::group(['prefix'=> '/task','as'=>'task.'] , function ( ) {
Route::get('/list',[TaskController::class,'index'])->name('list');
Route::post('/create',[TaskController::class,'create'])->name('create');
Route::post('/update/{task}',[TaskController::class,'update'])->name('update');
});
We can simply call this named routes from blade file this way
{{route('task.create')}}
But if these same lines are in routes/api.php
How can we call in blade file. I tried this way
{{route('api.task.create')}}
CodePudding user response:
You need to specify the name as well in the routes\api.php
file
Route::group(['as'=>'api.'] , function ( ) {
Route::group(['prefix'=> '/task','as'=>'task.'] , function ( ) {
Route::post('/create',[TaskController::class,'create'])->name('create');
});
});
so you can call it like this:
{{route('api.task.create')}}
you may check: php artisan route:list
to see the name assigned to double check.
CodePudding user response:
Laravel combines the routes whatever it is in web.php or in route.php.
so we can use the same pattern in blade to call named route of api.php
{{route('task.create'}}