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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community