When I try to echo and display the output of a query in my dashboard it is appearing like this
[{"job_type":"Sales Manager"}]
The query is this:
->where('id',$userId)
->select('job_type')
->get();
To display it on the dashboard I am using this code
<div >
<div >
<div >
<h1 ><i ></i></h1>
<h5 >{{ $jobType }}</h5>
<h6 >Designation</h6>
</div>
</div>
</div>
How do I just get the result instead of the variable name along with the brackets?
CodePudding user response:
You can use this query
->where('id',$userId)
->pluck('job_type')
->first();
CodePudding user response:
You should print it like {{$jobType->job_type}} or {{$jobType['job_type']}}
based on your return type.
CodePudding user response:
->where('id',$userId)
->select('job_type')
->get();
This code will return Collection instance so you should either use first(); or you iterate over the variable. You probably try to get the user so you should use it like this:
$user = User::where('id', $userId)->first();
and use below code in your view
{{ $user->job_type }}
Or you can use
$user = User::find($userId);