grohiro / laravel-camelcase-json

Convert response JSON key to camelCase
MIT License
27 stars 4 forks source link

Deprecated function camel_case in Laravel 5.7+ #8

Closed nunar closed 4 years ago

nunar commented 4 years ago

Since global string and array helpers are deprecated (Laravel news) this package isn't working anymore with newest versions of Laravel.

Proposed solution

use Illuminate\Support\Str;

public function encodeArray($array)
{
    $newArray = [];
    foreach ($array as $key => $val) {
        // Deprecated
        // $newArray[\camel_case($key)] = $this->encodeJson($val);

        // Use this directly
        $newArray[Str::camel($key)] = $this->encodeJson($val);
    }
    return $newArray;
}

Another workaround since pull request is still open:

app/Http/Helpers.php

use Illuminate\Support\Str;

if (!function_exists('camel_case')) {
    function camel_case($input)
    {
        return Str::camel($input);
    }
}
nunar commented 4 years ago

Fixed with version 2.0.