Another thing I noticed is how OrderController is returning response()->json() everywhere:
app/Http/Controllers/Api/OrderController.php:
public function show($order_id){ // ... return response()->json(new OrderResource($order), Response::HTTP_OK);}
The thing is that if Laravel detects the API call, it automatically returns JSON, so you don't need to specify this manually.
The Response::HTTP_OK (200 status code) is also returned automatically by Laravel.
So, in this case, the "Laravel way" code would be just this:
app/Http/Controllers/Api/OrderController.php:
public function show($order_id){ // ... return new OrderResource($order);}
The only reason why it may be beneficial to specify response()->json() and the status code is if the...
Order::filter($filter) filter() method is not defined. i have not found it. is it method provided by laravel?
This method comes from a model scope:
Within Laravel, this will get transformed to Order::filter() sine it drops the
scopeand just uses theFilterpartwhere i can read about it in documentation becouse i have only found local scope but there is #[Scope] not scopeFunction.
It's the same thing!
The scopeFunction was there before we even had the attributes (the #[Scope] thing). So they work identically, and you can find them in Laravel 11 documentation: https://laravel.com/docs/11.x/eloquent#local-scopes