This is my web routes:
Route::group([
'middleware' => 'proveedor_auth'
], function ($router) {
require base_path('routes/custom/proveedor_routes.php');
});
Route::group([
'middleware' => 'tendero_auth'
], function ($router) {
require base_path('routes/custom/tendero_routes.php');
});
I tried with Route::Group but just only works with "tendero_auth".
There is other better way?
proveedor_auth:
public function handle($request, Closure $next)
{
if (Auth::guard('web_proveedor')->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('log');
}
}
return $next($request);
}
tendero_auth:
public function handle($request, Closure $next)
{
if (Auth::guard('web_tendero')->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('log');
}
}
return $next($request);
}
Or is there some library to do this for me?
tendero_routes.php
Route::get('/', function () {
return view('tendero.index');
});
proveedor_routes.php
Route::get('/', function () {
return view('proveedores.index');
});
My idea is change later the annonymous function by a ResourceController. This is only for testing.
So obviously the second one overwrites the first.
Route::group(['middleware' => 'web'], function() {
Route::get('/', function () {
return view('tendero.index');
});
});
Route::group(['middleware' => 'auth'], function() {
Route::get('/', function () {
return view('proveedores.index');
});
});
when doing the php artisan route:list
there will be only the second listed:
php artisan route:list
+--------+----------+-----+------+---------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----+------+---------+------------+
| | GET|HEAD | / | | Closure | auth |
+--------+----------+-----+------+---------+------------+
It seems to be also confirmed here: https://laracasts.com/discuss/channels/laravel/multiple-routes-with-same-url-but-different-names
I believe that URLs are indexed and keyed on their URL - so therefore the first one would be overridden completely by the first one.