Laravel Call to undefined method App\\ Model ::mapInto(), vendor\\laravel\\framework\\src\\Illuminate\\Support\\Traits\\ForwardsCalls.php

允我心安 提交于 2020-12-15 10:25:19

问题


I'm trying to

public function show(Product $product)
{
    return ProductDetailResource::collection($product);
}
  

Call to undefined method App\ Model ::mapInto(), exception: BadMethodCallException file vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php

then google and cant find any results


回答1:


just need to replace

public function show(Product $product)
{
    return ProductDetailResource::make($product);
}

instead of:

public function show(Product $product)
{
    return ProductDetailResource::collection($product);
}
  

because collection for $products and collection of product.

but we have one item here



来源:https://stackoverflow.com/questions/62852660/laravel-call-to-undefined-method-app-model-mapinto-vendor-laravel-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!