Can you try this?
App\Activity::whereIn('id', [16,25,50])->get(['id', 'name->>en'])
Hello everybody, long time lurker and found some awesome answers, however this time I encountered what seems unusual problem. My setup: Laravel 6.16 Mysql 8.0.19
I have an Activity table and model with json column name and when I try to query it I get this
>>> App\Activity::whereIn('id', [16,25,50])->get(['id', 'name->en'])
=> Illuminate\Database\Eloquent\Collection {#3034
all: [
App\Activity {#3035
id: 16,
json_unquote(json_extract(`name`, '$."en"')): "8844ge32v",
},
App\Activity {#3036
id: 25,
json_unquote(json_extract(`name`, '$."en"')): "21972qf55",
},
App\Activity {#3037
id: 50,
json_unquote(json_extract(`name`, '$."en"')): "700z48306",
},
],
}
You need a single arrow and an alias:
App\Activity::where('id', 1)->get('name->en as name')
Please or to participate in this conversation.