i would like to know how to get work API call with ResourceCollection
Error :
Undefined property: Illuminate\Database\Query\Builder::$name
my product method :
public function index()
{
return ProductCollection::collection(Product::all());
}
my collection :
public function toArray($request)
{
//return parent::toArray($request);
return [
"name" => $this->name,
"price" => $this->price,
"href" => [
"link" => route("product.show", $this->id)
]
];
}
tryed it just by Resourse ( not ResourceCollection ) just modifed method call and its was working but i need know how to fix ResourceCollection return new ProductResource($product);
error snap :
Change
use Illuminate\Http\Resources\Json\ResourceCollection;
class ProductCollection extends ResourceCollection
{
to
use Illuminate\Http\Resources\Json\Resource;
class ProductCollection extends Resource
{
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With