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

Problem if receiving camelCase input #67

Closed stefensuhat closed 7 years ago

stefensuhat commented 7 years ago

for example:

{firstName: "Example", email: "example@example.com", password: "asdasd"}

On saving to database , the firstName value is not saved. I see you have setAttribute function but seems to not working convert it to snake case.

kirkbushell commented 7 years ago

Can you provide more information? This project is used by quite a few and the key feature is camel cased fields.

stefensuhat commented 7 years ago

@kirkbushell I'm building an SPA project with laravel as backend.

From my front end i send this data {firstName: "Example", email: "example@example.com", password: "asdasd"} but on receiving to the server, I can only saved the email and password. the firstName input is being ignored (because may be the database column is first_name).

kirkbushell commented 7 years ago

You need to provide some code. I am unable to reproduce this and use the library on a 500k lines project with no issues with camel casing. I also run a SPA with laravel as backend.

My first assumption is you're not including the trait or extending a base model that includes it.

stefensuhat commented 7 years ago

@kirkbushell at my model User.php

class User extends Authenticatable
{
    use Notifiable, CamelCasing, Uuid;

    protected $fillable = [
        'name', 'email', 'first_name', 'last_name', 'gender', 'phone'
    ];

}

my controller only simple:

$user = new User($request->all());
$user->save();
kirkbushell commented 7 years ago

You're not using camel case in your fillable attributes.