Skip to content

Instantly share code, notes, and snippets.

@jasonmccreary
Created October 26, 2018 14:56
Show Gist options
  • Save jasonmccreary/013dcd294da0f7eb8059d44120f0ad3e to your computer and use it in GitHub Desktop.
Save jasonmccreary/013dcd294da0f7eb8059d44120f0ad3e to your computer and use it in GitHub Desktop.
Regex to convert old closure based view routes to Route::view()

The following regex will convert old, closure-based view routes from:

Route::get('faq', function () {
    return view('faq');
});

to the new, cacheable Route::view() introduced in Laravel 5.5.

Route::view('/faq', 'faq');

Check out this tweet for more details.

Search String

Route::get\('([^']+)', function \(\) \{\s+return view\('([^']+)'\);\s+\}\)

Note: assumes well-formatted code.

Replacement

Route::view('/$1', '$2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment