Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for negating route filter patterns with ! #559

Merged
merged 7 commits into from Sep 23, 2022

Conversation

bakerkretzmar
Copy link
Collaborator

@bakerkretzmar bakerkretzmar commented May 6, 2022

Adds support for filtering out certain route names by prefixing a pattern with !. If all provided patterns are negated, the patterns are treated as 'reject' rules, starting with all routes included by default and using the patterns to filter them out, which is how except works now.

Addresses #520 and #555 because groups now support both including and excluding routes. The existing functionality behaves like only, so the key addition would be a way to exclude routes, which this PR accomplishes:

// Current usage, behaves like `only`
config(['ziggy.groups' => [
    'viewer' => [
        'posts.*',
    ],
]]);

// Added in this PR, behaves like `except`
config(['ziggy.groups' => [
    'guest' => [
        '!posts.*',
    ],
]]);

// Also added in this PR鈥攎ix and match! Behaves like `only` but additionally excludes negated patterns
config(['ziggy.groups' => [
    'viewer' => [
        'posts.*',
        '!posts.comments.*',
    ],
]]);

This does make the top-level except key a bit redundant, but that lines up nicely with my plan in v2 to combine 'only', 'except', and 'groups' into one feature 馃憖

@YeeJiaWei thoughts? Your original example in the discussion would now look like this:

return [
    'groups' => [
        'inertia' => ['!_debugbar.*', '!debugbar.*', '!ignition.*', '!admin.*'],
    ],
];

Closes #555.

@YeeJiaWei
Copy link
Contributor

@bakerkretzmar I think this is also acceptable approach

@bakerkretzmar bakerkretzmar merged commit 99b7beb into main Sep 23, 2022
@bakerkretzmar bakerkretzmar deleted the jbk/filter-negation branch September 23, 2022 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants