Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!