Support the ongoing development of Laravel.io →
Database Eloquent Testing
Last updated 2 years ago.
0

Model::find($id) method can return either a Model, a Collection of models (if you pass it an array of ids as the first argument), or null. Scrutinizer can't know which of these will be returned, so it warns you that in case of Collection you'll be calling non-existing method.

It's not an error, if you are sure that $dataContainer->id will never be an array. Maybe if you cast it to string explicitly, the Scrutinizer can figure out that find() will return either Model or null, but never Collection. But I'll be surprised if that's the case as it will require some non-trivial (not as trivial as just checking possible returned types/classes) code analysis.

0

I tried to cast the $dataContainer->id to int but it does not change anything :( ...

$post = Post::find((int) $dataContainer->id);
$post->upload_path = $uploadPath;
 $post->save();
The method save does only exist in Illuminate\Database\Eloquent\Model, but not in Illuminate\Database\Eloq...ase\Eloquent\Collection.
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

cboelter cboelter Joined 22 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.