@xis json api's should respond with camelCase.
If you use API Resources you can do this on a model per model basis
https://laravel.com/docs/8.x/eloquent-resources
eg..
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'firstName' => $this->first_name,
'lastName' => $this->last_name,
];
}
to convert to snake_case on the way back in, you can do:
use Illuminate\Support\Str;
$converted = Str::snake('fooBar');
although, I would be explicit and just manually convert
eg
$model = Foo::create(
[
'first_name' => $request->firstName,
'last_name' => $request->lastName
]
)