jypersona
jypersona

Reputation: 49

Curly brackets are appearing along with the variable name when I try to echo on laraval

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

Answers (3)

gguney
gguney

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

Swalih VM Bazar
Swalih VM Bazar

Reputation: 66

You can use this query

->where('id',$userId)
    ->pluck('job_type')
    ->first();

Upvotes: 2

Kiran Rai Chamling
Kiran Rai Chamling

Reputation: 508

You should print it like {{$jobType->job_type}} or {{$jobType['job_type']}} based on your return type.

Upvotes: 1

Related Questions