codeistalk's avatar

Undefined property: Illuminate\Database\Query\Builder::$map

HI

This is the first time I am dealing with API Resources in Laravel. I have create Resource Collection and using it's default definition. Changed nothing.

With pagination it's working awesome. When I call /model/{id}, it gives error

Undefined property: Illuminate\Database\Query\Builder::$map

I have added a screenshot of error too.

http://www.openscreenshot.com/#/i/B1ziEDVaf

public function show(Language $language) {
        return new LanguageCollection($language);
    }

Thanks

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

The issue is that you are giving a Model instance to a ResourceCollection instance. You would need a separate resource class to represent the single model instance:

public function show(Language $language) {
    return new LanguageResource($language);
}

codeistalk's avatar

oh.... I thought same collection can work for both. Thanks you so much. This fixed problem

irsyadadl's avatar

Just rename the class, if any error come, just run composer dump-autoload in your terminal.

Please or to participate in this conversation.