问题
I have a model where column location represents coordinates.
This column can be null. When it is null everything is fine, but when there is some data, then:
If it is used inside internal laravel events (which does not implement ShouldBroadcast) then I have to add
use SerializesModels, otherwise field is not deserialized, exception is throwninvalidPayloadException in Queue.php line 89If it ised inside
broadcastlaravel events (which must be delivered into browser) then node.js fails to parse it.
Example: location is null
Event:
{"event":"App\\Events\\ViewingUsersUpdated","data":{"users":[{"id":1,"created_at":"2017-04-12 07:20:16","updated_at":"2017-04-12 07:20:16","creator_id":null,"phone":"70000000000","first_name":"\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 1","last_name":"","middle_name":"","active":1,"manager_id":null,"avatar":"\/img\/profile.png","full_name":"70000000000 \u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 1 ","user_timezone":"Europe\/Moscow"}],"instance":{"id":1,"created_at":"2017-04-12 11:29:06","updated_at":"2017-04-12 13:55:32","creator_id":1,"test_field_text":"1234567892131","user_field_single":null,"image_single":null,"location":null,"address_area":"b8837188-39ee-4ff9-bc91-fcc9ed451bb3","address_region":null,"address_city":"f66a00e6-179e-4de9-8ecb-78b0277c9f10","address_locality":null,"address_street":null,"modelType":"testing"}},"socket":null}
location is not null
Event:
undefined:1
P.S.
Mutator:
$this->attributes[$key] = DB::raw('POINT(' . $value . ')');
Accessor:
$value = unpack('Lpadding/corder/Lgtype/dlatitude/dlongitude', $value);
$value = $value['latitude'] . ',' . $value['longitude'];
来源:https://stackoverflow.com/questions/43371890/laravel-fails-to-deserialize-model-with-mysqls-point-column