#Property does not exist on this collection instance.

28 messages Β· Page 1 of 1 (latest)

scenic sphinx
#

#rules

static kite
scenic sphinx
static kite
#

I'm trying to view some data.

Controller

public function show_2(){
        $company=DB::table('companies')->where('id' , '=' , '2');
        return view('application.apply', [
            'provider_id'=>2,
            'company'=>$company->get()
        ] );
    }

Blade

<x-company-info :company="$company" />

The component

@props(['company'])
<h2> {{ $company->name }} </h2>
<p> {{ $company->details }} </p>

Attached screeshoots for the dd() result, and the error

dreamy valley
#

You are loading a collection of items, no wonder it throws errors

#

If you want a single result, either get the first() at the end OR even better - use the find() method for the query builder

static kite
#

I did the exact same thing here

@props(['latest'])
<x-card>
    <div class="flex flex-col">
        <h5> {{ $latest->title }} </h5>
        <p> {{ $latest->details }} </p>
    </div>
</x-card>

And it's working!

dreamy valley
#

Ye sure

static kite
#

But why, i don't get it

scenic sphinx
#

This line is the problem:

$company=DB::table('companies')->where('id' , '=' , '2');
#

If you want to get a single company with that ID, then use Eloquent models and build a proper query:

$company = Company::findOrFail(2);
#

But I don’t know why you’d be looking up models with hard-coded IDs like that in the first place.

static kite
#

Controller for the apove code

public function list(Request $request){
        $application =DB::table('applications')->where('provider_id' , 'like' , Auth::Guard('providerg')->id() );
        dd($application->get());
        return view('providers.applications' ,[
            'applications'=>$application->get()

        ]);
    }
dreamy valley
dreamy valley
#

You are passing applications collection and above code is using $latest variable

scenic sphinx
static kite
#

Not to this sorry

dreamy valley
dreamy valley
#

What can I say, it's such a bad name for a method xd

static kite
#

How was i thinking πŸ˜­πŸ˜‚, k nvm how can i delete this

scenic sphinx
#

Delete what?