Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel route redirect without closure for route cache

I have this code on my routes.php file that do a redirect. Though the problem is that whenever I ran php artisan route:cache command, it gives me an error of Unable to prepare route [article/{params}] for serialization. Uses Closure.

I know this has something to do with routes not allowing it to be cached if it have a closure. But how could I make a workaround for this redirect?

Route::get('article/{params}', function($params) {
    return Redirect::to($params, 301);
});
like image 743
basagabi Avatar asked Feb 24 '16 21:02

basagabi


Video Answer


1 Answers

Since Laravel 5.5 you can use:

Route::redirect('/here', '/there', 301);

See the documentation under Redirect Routes.

like image 55
thijsai Avatar answered Oct 27 '22 14:10

thijsai