Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
Is there a way to use Laravel's getRoutes() to only return routes that aren't redirects?

I've been trying to use Laravel's Route::getRoutes() method to generate a dynamic sitemap. The problem is that that method returns routes that are in reality redirects:

Example web.php:

Route::get('not-redirected', function() {
    return view('not-redirected');
}

Route::get('redirected', function() {
    return redirect('was-redirected');
}

Route::getRoutes() returns ['not-redirected', 'was-redirected']. Is there a way to dynamically filter out redirected routes from this output?

My desired output for the above web.php would be ['not-redirected'].

EDIT: I've noticed that php artisan route:list does not return redirects. However, I can't figure out why just by looking through the source code... It looks like it calls that same function, Route::getRoutes().

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It seems there is no way to determine the return for a given route. The solution I came up with is to add a group all the routes that are 'special', this way you can easily add custom attributes to a route's action.

Route::group(['return_type' => 'redirect'], function () {
    Route::get('not-redirected', function () {
        return view('not-redirected');
    });

    Route::get('redirected', function () {
        return redirect('was-redirected');
    });
});

Then you could loop over the routes like this:

$routes = Route::getRoutes()->get();
foreach ($routes as $route) {
    if ($route->getAction('return_type') === 'redirect') {
        // Or whatever you want to do in this case
        continue;
    }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda