#Property does not exist on this collection instance.
28 messages Β· Page 1 of 1 (latest)
Should i make it as snippets or what? π
You should post code blocks like the rules say and demonstrate.
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
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
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!
Ye sure
But why, i don't get it
Because you need a pass a single model instance, and not a collection.
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.
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()
]);
}
It's "show_2* so it makes sense 
Not true
You are passing applications collection and above code is using $latest variable
@static kite Think you need to start here: https://laravel.com/docs/9.x
I feel attacked π
Not to this sorry
Good 
Here
XD
What can I say, it's such a bad name for a method xd
How was i thinking ππ, k nvm how can i delete this
Delete what?