•
32 min read
Route functions cheatsheet
Laravel comes with a number of helpers around the routes and current request which we can use to compare the current page with navigation links and breadcrumbs to determine active states etc.
We will mostly be using the route class Illuminate\Routing\Route
via the facade Illuminate\Support\Facades\Route
and the request class Illuminate\Http\Request
with the request()
helper.
Route
Current
Name
Is
Action
Parameters
\Request::route()->parameters
List
Previous route name
You could add this to the Route macros (or helpers file) to make it available as a shortcut:
URL
Current
Is
Segment
Query string
Components
Further reading
Keep an eye out for an article about route parameter binding in Laravel soon where we will look at how Laravel resolves a route, binds parameters (including implicit model binding) and executes middleware before passing to a controller or closure.