Overview
Ziggy’sroute() function works like Laravel’s route() helper—you can pass it the name of a route, and the parameters you want to pass to the route, and it will generate a URL.
Function Signature
Theroute() function accepts up to four parameters:
Parameters
The name of the Laravel route you want to generate a URL for.
Route parameters to substitute into the route’s URI template. Can be passed as:
- A single value (string or number)
- An array of values
- An object with parameter names as keys
Whether to include the URL origin (domain) in the generated URL. Set to
false to generate a relative path.Ziggy configuration object. When using the
@routes Blade directive, this is available globally and doesn’t need to be passed.Return Value
Theroute() function returns:
- String: A fully-formed URL when called with a route name
- Router instance: A
Routerclass instance when called with no arguments, providing access to additional methods likecurrent(),has(), and theparamsproperty
Basic Usage
Generate a simple URL:With Route Parameters
Working with the Router Class
When called without arguments,route() returns a Router instance:
Practical Examples
HTTP Request with Axios
Navigation Links
Form Actions
Error Handling
When using the
@routes Blade directive, Ziggy’s configuration is available globally. If you’re importing Ziggy manually (e.g., in a SPA), you’ll need to pass the configuration as the fourth parameter.Next Steps
Route Parameters
Learn how to pass parameters to routes
Query Parameters
Add query strings to your URLs