Reputation: 49
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 class="col-md-6 col-lg-2 col-xlg-3">
<div class="card card-hover">
<div class="box bg-cyan text-center">
<h1 class="font-light text-white"><i class="mdi mdi-view-dashboard"></i></h1>
<h5 class="m-b-0 m-t-5 text-white">{{ $jobType }}</h5>
<h6 class="text-white">Designation</h6>
</div>
</div>
</div>
How do I just get the result instead of the variable name along with the brackets?
Upvotes: 0
Views: 384
Reputation: 2663
->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);
Upvotes: 0
Reputation: 66
You can use this query
->where('id',$userId)
->pluck('job_type')
->first();
Upvotes: 2
Reputation: 508
You should print it like {{$jobType->job_type}} or {{$jobType['job_type']}}
based on your return type.
Upvotes: 1