Larastan: Eloquent\Collection::map()'s return type

Created on 28 Aug 2019  路  7Comments  路  Source: nunomaduro/larastan

  • Larastan Version: #.#.#
  • --level used:

Description

17 Call to an undefined method Illuminate\Support\Collection::makeHidden().

The doc-tag of \Illuminate\Database\Eloquent\Collection::map() says @return \Illuminate\Support\Collection|static - so it warns me for the case that the map() returns a base collection?

Laravel code where the issue was found

UserSession::with('user')->get()->map(function (UserSession $userSession) {
        $userSession->setAttribute('user_email', $userSession->user->email);
        $userSession->setAttribute('user_name', $userSession->user->full_name);

        return $userSession;
})->makeHidden('user')
bug

Most helpful comment

Ah, sorry my bad. So it thinks it returns Illuminate\Support\Collection not Illuminate\Database\Eloquent\Collection

I made a fix for the return type of get. I'll open the PR today. Then we'll see :+1:

All 7 comments

Where is makeHidden defined? Is it a custom Collection macro?

Ah, sorry my bad. So it thinks it returns Illuminate\Support\Collection not Illuminate\Database\Eloquent\Collection

I made a fix for the return type of get. I'll open the PR today. Then we'll see :+1:

While https://github.com/laravel/framework/pull/30239 got merged into 6.3 I am seeing the same with a get() call on Eloquent queries. Testing a few things out this hopefully gets resolved with https://github.com/nunomaduro/larastan/pull/325 as it only happens when using where statements.

Can you test this with the latest changes in master branch?

I am no longer seeing the issue with dev-master.

Thanks @spaceemotion ! Good job @canvural

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jdrieghe picture jdrieghe  路  4Comments

mariomka picture mariomka  路  4Comments

bogdankharchenko picture bogdankharchenko  路  4Comments

zlodes picture zlodes  路  3Comments

Braunson picture Braunson  路  4Comments