coderello / laravel-shared-data

📦 An easy way to share the data from your backend to the JavaScript.
https://coderello.com/docs/laravel-shared-data/1.0/sharing-data
MIT License
321 stars 22 forks source link

Key transformer #11

Closed hivokas closed 5 years ago

hivokas commented 5 years ago

It would be handy to have an ability to specify the key transformer:

SharedData::keyTransformer(function ($key) {
    return Str::camel($key);
});

So that:

share(['auth_user' => auth()->user()]);

Will be transformed into:

{
    "authUser": {
        "id": 1,
        "firstName": "Ilya",
        "lastName": "Sakovich"
    }
}
klimov-paul commented 5 years ago

I would say it is an unnecessary overcomplication. If someone wishes to use camel case instead of snake case it is better to be changed outside SharedData. Creating extra magic here will simply confuse developer.

hivokas commented 5 years ago

Well, agreed.