Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tomasz_Kisiel's avatar

Laravel resource controller.

In my app controller I have method e.g like this:

public function destroy( Book $book ) { ... }

and route like this:

Route::resource('books', BookController::class);

I want to send request from my spa app to the server but I'm confused .. how should I pass Book object from React app to Laravel api ?

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

It should be the id of the Book; so you are making a DELETE request from your React app to /books/123 where 123 is the id of a Book model. Laravel's Route-Model binding will attempt to find a Book instance based on the id in the URI.

andyandy's avatar

Put in console this

php artisan route:list

It will show you all urls and ho to call them

Tomasz_Kisiel's avatar

Thanks.. I tried this firstly but this didn't work for me and I got exception with message that route expected Book object but string was given.

My problem was that I had route that take subdomain as param and unfortunetly this was pass to the controller insted of book id.

Thansk one more time :)

Please or to participate in this conversation.