7 months ago

how to access json column in laravel

Posted 7 months ago by adeguntoro

i edit laravel default user migration and i add meta column, and this meta column is where i save my data in json format. But now i'm bit confuse how to access this column. I use standar eloquen to get data from database

$website = User::find(1);
return view('website.index')->with('website',($website));

then in my blade file, i try this

{{ $website->meta->gender }}

and it give me error

Trying to get property 'gender' of non-object

i also try another method from stackoverflow ( :

$website = User::find(1);
return view('website.index')->with('website', json_decode($website, true));

//blade file
@foreach($website->meta as $member)
    gender: {{ $member['gender'] }}

but also it give me error

Array to string conversion 

and this is my current output if i use return view('my.blade, compact('mydata'))

///{!! $website !!}

email_verified_at: "2020-02-13 12:22:56",
status: "1",
meta: {
gender: "Male",
country: "Antarctica (the territory South of 60 deg S)",
biodata: "The Dormouse had closed its eyes again.",
address: "11481 Kelsie Dale Port Humberto, SC 94117-0111",
parents: {
mother: "Miss Juliana Williamson",
father: "Dell Franecki",
kids: {
number1: "Waldo Schiller",
number2: "Angelita Smith",
number3: "Ladarius Witting"
skills: [

and i already cast my meta as array. So, how can i access my json column in laravel ?

Please sign in or create an account to participate in this conversation.