-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Adds support for implicit route model binding with translated slugs #213
Conversation
Seems interesting, but currently tests and updated readme seem to be missing. Could you take care of that? |
…on operations Fixes invalid model binding when field is set
@freekmurze Thanks for the reply. I updated the readme and added a brief explanation. Unfortunately I was unable to add test cases because sqlite doesn't support json without the JSON1 extention. I added a try-catch block around the added operation to avoid conflicts with databases that don't support json. |
In that case, we'll need to switch to using MySQL for the tests. Currently I don't have the time to take care of this, but I accept a separate PR that does this. |
Turns out I didn't read the laravel docs about |
…licit-model-binding
Fixes typo
Fixes typo
…licit-model-binding # Conflicts: # src/HasTranslatableSlug.php
Let me know when this is ready for review. |
I added some questions to your change request comments where I was unsure what to do. Except that, it's ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going in the right direction 👍
I just realized that my comments mentioned above where still pending 🙈. I'll take care of the change request this evening |
@freekmurze As you mentioned in the review comment, child model resolution was not working correctly as it is only handled by the parent model. I created a PR which fixes this problem: laravel/framework#39929 . This however means that implicit route model binding only works from the next release (probably v8.76.0+). |
Instead of checking for the specific Laravel version number (and adding a note), feel free to update the required Laravel version in composer.json 👍 Seems like the tests are failing, could you take a look at that? |
I can do that for laravel framework v8 but not for v7.
The test fails because the version I check on should be replaced with the next release. I tested with |
Let's just drop support for Laravel 7.
Great, thanks! Feel free to poke me again then. |
I updated the framework version to @freekmurze Do you think it would be useful to not only query for the current locale but for all enabled locales to better support url sharing? Currently url sharing is only possible within the same locale. |
I think just enable this for the current locale is fine 👍 Thanks for your work on this PR. |
@freekmurze First of all thanks for merging
I need this for a project anyway. The question is if you'd like to have this as a feature in this project and what your opinion on a separate table to improve querying is. My idea would be like this:
This could be a PR for laravel-translatable as well but I think it is intended to keep it as json for simplicity. Alternatively I could also image to query the model like this: foreach ($locales as $locale) {
$query->orWhere("{$field}->{$locale}", $value);
} But afaIk, it is bad practice to query with json like this |
@@ -17,7 +17,7 @@ | |||
], | |||
"require": { | |||
"php": "^8.0", | |||
"illuminate/database": "^8.0", | |||
"illuminate/database": "^8.76.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sail@f34348e1ecf9:/var/www/html$ composer require spatie/laravel-sluggable
Using version ^3.2 for spatie/laravel-sluggable
./composer.json has been updated
Running composer update spatie/laravel-sluggable
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires spatie/laravel-sluggable ^3.2 -> satisfiable by spatie/laravel-sluggable[3.2.0].
- spatie/laravel-sluggable 3.2.0 requires illuminate/database ^8.76.1 -> found illuminate/database[v8.76.1, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other packages do you use? And which version do you use for your project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds implicit route model binding support for translated slugs using spatie/laravel-translatable if the route key matches the slug field