kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

CamelCasing and firstOrNew, firstOrCreate, etc. methods #43

Closed cviebrock closed 8 years ago

cviebrock commented 8 years ago

I'm pretty sure these methods don't work with camel-casing enabled on the model, since the array of attributes passed to each is simply passed through to the where() clause of a query.

I think the fix is reasonably simple: overload all these methods in the CamelCasing trait, snake_case all the array keys, then return the parent method.

Not sure if that's the best way to do it, though. Thoughts?

kirkbushell commented 8 years ago

That's definitely the best way.

cviebrock commented 8 years ago

There you go. :)

cviebrock commented 8 years ago

Not entirely related, but this doesn't work either (if the $data array has camel-cased keys):

$model = MyCamelCasedModel::where($data)->get();

I think the fix here is rather larger... :worried:

kirkbushell commented 8 years ago

Yeah I won't or wouldn't bother with that - that's dealing directly with the query builder then.

kirkbushell commented 8 years ago

CamelCase functionality was there initially just to deal with JSON responses, and it grew substantially.