Comments (7)
@brendt I'll see if I can find some time this week to test my initial thoughts and I'll ping you a PR.
from laravel-binary-uuid.
Hey and thanks for reporting this issue!
This is kind of a difficult one to tackle, because if we're not overriding getRouteKeyName
, you'll get binary encoded values in generated URLs if I'm not mistaken.
The encoding and decoding needs to happen somewhere, and I'm not a 100% sure where the best place for it should be. A middleware seems like the correct place, but you would still need to add it to your routes using UUIDs in URLs.
Do you see other solutions which might solve your case in a better way?
from laravel-binary-uuid.
Hey Brendt, I'm not too familiar with the 'url generation' part that you mentioned, do you mean when doing something like
url("/posts/{$post->id}")
?
from laravel-binary-uuid.
In that case you're manually generating URLs, but if you're using route model binding, Laravel will automagically resolve things for you. Without overriding getRouteKeyName
, the binary ID will be used, which we don't want.
from laravel-binary-uuid.
I was just looking into this issue myself for my own project.
I was tempted to make a tweaked version of the Illuminate\Routing\Middleware\SubstituteBindings
middleware & related classes which will can look up the model by the binary UUID - this would potentially cause issues with non-uuid models.
Alternatively and probably much easier would be to overwrite the resolveRouteBinding
function from the Model
class:
/**
* Retrieve the model for a bound value.
*
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function resolveRouteBinding($value)
{
// return $this->where($this->getRouteKeyName(), $value)->first();
return $this->where($this->getRouteKeyName(), self::encodeUuid ($value))->first();
}
This overwritten method could be included in the HasBinaryUuid
trait quite easily. Not tested the above yet but I figured I'd share my thoughts.
from laravel-binary-uuid.
@slashequip If you're up for it, feel free to send a PR, we might indeed merge this instead of overriding getRouteKeyName
.
There's also talk to add binary UUIDs and binding support in Laravel itself, though it's nowhere near concrete yet. That would of course be the best solution.
from laravel-binary-uuid.
#36 was merged and tagged: https://github.com/spatie/laravel-binary-uuid/releases/tag/1.1.5
from laravel-binary-uuid.
Related Issues (20)
- Using pivot tables help with uuid
- [Idea] Split up HasBinaryUUID trait HOT 2
- Laravel Scout: Issue with newQueryForRestoration($id) (Add Array Support) HOT 2
- Composite Key Not Working HOT 18
- with('relation') . cause utf8 encode error HOT 5
- Malformed UTF-8 characters, possibly incorrectly encoded HOT 4
- Ordered UUID for Laravel MySQL grammar query compilation via custom builder HOT 1
- Running DB::purge() is unloading extension HOT 3
- uuid() blueprint method creates a char(36) column instead of binary(16) HOT 1
- Use ID and UUID HOT 1
- Usage with Laravel Nova HOT 5
- Question - Should I still have a fk defined $casts? HOT 2
- General error: 1215 Cannot add foreign key constraint when using relations HOT 2
- Relies on static UUID factory not being changed HOT 3
- Lack of "ID" in key name results in exception HOT 1
- Can we have an incremental id (for internal relations) too? HOT 1
- Relation model saving causes "UTF-8" Error HOT 2
- Conflict with Laravel Telescope HOT 1
- Disable blueprint override HOT 1
- Looking for maintainers / abandonment notice HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-binary-uuid.