Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

419
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda