Configuring Groups
Define groups in yourconfig/ziggy.php file using the groups key:
config/ziggy.php
only and except filters.
Using Groups with @routes
Expose a specific group by passing the group name to the@routes Blade directive:
authors.blade.php
author group: all posts.* and categories.* routes.
Example: Different Routes for Different Layouts
guest.blade.php
admin.blade.php
Multiple Groups
You can expose multiple groups on the same page by passing an array of group names:admin-authors.blade.php
admin and author groups.
Merging Groups
When multiple groups are passed, Ziggy merges all patterns from all specified groups:config/ziggy.php
Group Patterns
Groups support the same pattern matching as route filters:Wildcards
config/ziggy.php
Exact Matches
config/ziggy.php
Mixed Patterns
config/ziggy.php
Negative Patterns in Groups
You can use negative patterns (prefixed with!) to exclude specific routes from a group:
config/ziggy.php
All Negative Patterns
You can create groups using only negative patterns to include everything except specified routes:config/ziggy.php
Mixing Positive and Negative Patterns
config/ziggy.php
posts.show, posts.store, posts.update, etc., but not posts.index.
Group Precedence
If you have both groups and global filters configured:config/ziggy.php
admin group will be used, and the global except filter will be ignored.
Undefined Groups
If you pass a group name that doesn’t exist in your config, Ziggy will return all named routes:config/ziggy.php
Always verify your group names to avoid accidentally exposing all routes.
Real-World Examples
Role-Based Groups
config/ziggy.php
Feature-Based Groups
config/ziggy.php
API Version Groups
config/ziggy.php
Using Groups with JavaScript Frameworks
When generating Ziggy’s config file for JavaScript frameworks, you can specify which group to include:ziggy.js file containing only the routes from the author group.
Can I use multiple groups in ziggy:generate?
Can I use multiple groups in ziggy:generate?
The
--group option in the ziggy:generate command accepts a single group name. To include multiple groups, you’ll need to use the --only option with explicit patterns:How do groups interact with the filter() method?
How do groups interact with the filter() method?
The
group() method in Ziggy.php (src/Ziggy.php:60-77) processes groups by:- If an array is passed, it merges all patterns from all groups
- If a string is passed, it uses that single group’s patterns
- If the group doesn’t exist, it returns all routes
- Groups are processed through the same
filter()method that handlesonlyandexcept
only/except config when passed to @routes.What's the best way to organize groups?
What's the best way to organize groups?
Consider organizing groups by:
- User roles: Different routes for admins, editors, authors, guests
- Features: Group related functionality (blog, shop, account)
- Pages: Different routes for different page layouts
- Permissions: Match your authorization policies
Next Steps
Filtering Routes
Learn about route filtering patterns and wildcards
Blade Directive
Explore @routes directive options and parameters