laravel中的Json密钥格式更改

icomxhvb  于 2023-03-04  发布在  其他
关注(0)|答案(1)|浏览(129)

我创建了类似于此Json响应的API。

{
    "product_category_id": 1,
    "branch_id": 1,
    "product_category_code": "00184050",
    "product_Category_name": "books",
    "product_Category_imageURL": "books2.png",
    "product_Category_is_active": 1,
    "product_Category_created_at": "2023-02-25T10:55:48.000Z",
    "product_Category_updated_at": "2023-02-27T14:38:43.000Z",
    "product_Category__created_date": "2023-02-24T18:30:00.000Z",
    "product_Category_Created_by": 1,
    "product_Category_updated_by": 2
}

我需要这样的API。

{
    "productCategoryID": 1,
    "branchID": 1,
    "productCategoryCode": "00184050",
    "productCategoryName": "books",
    "productCategoryImageURL": "books2.png",
    "productCategoryIsActive": 1,
    "productCategoryCreatedAt": "2023-02-25T10:55:48.000Z",
    "productCategoryUpdatedAt": "2023-02-27T14:38:43.000Z",
    "productCategoryCreatedDate": "2023-02-24T18:30:00.000Z",
    "productCategoryCreatedBy": 1,
    "productCategoryUpdatedBy": 2
}

如何将此更改为整个应用程序有任何包的方法

l3zydbqr

l3zydbqr1#

你可以很容易地使用laraval助手类。

use Illuminate\Support\Str;
 
$converted = Str::camel('foo_bar');
 
// fooBar

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

相关问题