How to Override CartResource
suyashcyber94 last edited by
I have added a custom field in Cart for which I need to override CartResource to return my custom field, however, the resource is not injected in Webkul\API\Http\Controllers\Shop\CartController instead it is instantiated directly.
return response()->json([ 'data' => $cart ? new CartResource($cart) : null, ]);
Currently, I am overriding API routes and directing them to my custom CartController where I am using my Custom CartResource. This works fine but the issue is, I need to identify and override all the routes where cart is being return. Additionally, it is also not good if I will upgrade bagisto in the future as it will keep using the custom controller instead of core's (in case it is updated).
What is the right approach to this?
devansh-webkul last edited by
You are already doing with the right approach and this does not impact your upgrade unless and until you are changing the package's structure.
So, you need to handle the customization and also check the compatibility if you upgrade.