Answer the question
In order to leave comments, you need to log in
How to use UUID (binary16) in Laravel + mysql?
Hello. I have been suffering for two days now and I just can’t figure out how to make laravel and mysql work together .. in general, the task is that binary uuid, not string, would be used for any request to the database. Thus in views and other places - normal.
Options:
1) store it in the model as a string - not an option at all
2) store it in the model as a binary and convert it to a string if necessary (for example, by creating an accessor id_string). That's cool, but laravel didn't give it a thought - what if you need multiple uuid fields? For example in a pivot table? Even assuming that this problem can be solved with a bunch of crutches, in any case, the main one remains - the magic methods of the model.
Let me explain: the Eloquent model has a bunch of methods. But an even greater part hangs in the Eloquent Query Builder and is called by magic methods from the model .. the coolest thing is that the parameter is passed directly, and not through the model. That is, when you try to find a uuid in the form of a string, nothing will work, because the search will be by string.
And now the question is: how to make eloquent transform the fields before the request / after the request? In doctrine2, judging by the topics, this is done by creating a type .. in turn, it has two methods: "convertToPhpValue" and "convertToDatabaseValue".. Are there similar methods in some packages for Larry?
Answer the question
In order to leave comments, you need to log in
For requests wrap in DB::raw, plus crutches with hex2bin and back.
When selecting through pivot, the query can be supplemented
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question