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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fallback Locale and Additional Query Support to findBySlug #284

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

mkeremcansev
Copy link
Contributor

Add Fallback Locale and Additional Query Support to findBySlug

This PR enhances the findBySlug method in the HasSlug trait by introducing two key features:

  1. Fallback Locale Support
  • If the model uses the HasTranslatableSlug trait, the method now checks for a matching slug in both the current locale and the fallback locale (defined in the application's fallback_locale configuration).
  1. Additional Query Customization
  • A new $additionalQuery parameter has been added, allowing developers to pass a callable to customize the query further.

Example Use Case:

$model = MyModel::findBySlug('example-slug', ['id', 'name'], function ($query) {
    $query->where('status', 'active');
});

@freekmurze freekmurze merged commit 26bd614 into spatie:main Dec 9, 2024
14 checks passed
@freekmurze
Copy link
Member

Thanks!

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.

2 participants