lundi 30 septembre 2019

Odd Laravel apiResource routes issue

the route for my show function in an apiResource is not working, but if I overload the route and point to the function it works as expected.

resource route does note work

Route::apiResource('/delivery_handler/chat/','CartDeliveryListChatController');

working route

Route::get('/delivery_handler/chat/{id?}', function ($id) {
        return (new App\Http\Controllers\Api\CartDeliveryListChatController)->show($id);
    });

in my controller

    /**
     * @param $chatId
     * @return CartDeliveryListChatResource
     */
    public function show($chatId): CartDeliveryListChatResource
    {
        $data = CartDeliveryListChat::where('id',$chatId)->first();
        return new CartDeliveryListChatResource($data);
    }

the routes list

  | GET|HEAD  | api/v1/delivery_handler/chat/{id?}                  |                                   | Closure                                                                             | api          |
|        | GET|HEAD  | api/v1/delivery_handler/chat/{}                     | show                              | App\Http\Controllers\Api\CartDeliveryListChatController@show                        | api          |


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2mYCWas
via IFTTT

Aucun commentaire:

Enregistrer un commentaire