0

This is my object

$User = DB::table('user_app')
                ->where('id',$request->get('token'))
                ->select('account_type','address','card_bank','code_melli','shahr as city','family','id','mobile','name','phone','role','ostan as state','zip_code')
                ->first();

This is my json respons

"user_data": {
        "account_type": "real",
        "address": "سناباد",
        "city": null,
        "family": "حسینی",
        "id": 180,
        "mobile": "09371521106",
        "name": "الهام",
        "phone": "0513845555",
        "role": "usual",
        "state": {
            "id": 11,
            "name": "خراسان رضوی"
        },
        "zip_code": "91387"
    }

Now i want to put null property empty string for example instead of city put "" value for APIs... How could i do it

3
  • You can use a middleware which converts the json to array, and use array_walk_recursive to convert all null to empty string, and then convert back to JSON . This shall take care of all your APIs at one go Commented Jul 19, 2020 at 7:13
  • is there any example that i can see ?? Commented Jul 19, 2020 at 7:15
  • Does this answer your question? convert null values into empty string in laravel 5.4 Commented Jul 19, 2020 at 7:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.