Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel controller store data received in camel case format

I’m working with multiple controllers where I receive inputs in camel case format and I need to assign these properties to a model:

$scopeCommercial = new ScopeCommercial();
$scopeCommercial->lifetime_sales = $request->lifetimeSales;
$scopeCommercial->lifetime_volumes = $request->lifetimeVolumes;

The problem is that my model has around 30 properties and I don’t want to write them one by one.
I know that I can use the request to get all the properties:

$input = $request->all();

Is there a way to convert match the properties in camel case format with the database standard equivalent? Something like the inverse of camel method:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$converted = Str::camel('foo_bar');

>Solution :

Use

$converted = Str::snake('fooBar', '_');

more https://laravel.com/docs/8.x/helpers#method-snake-case

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading