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

alexrobinson's avatar

RESTful Resource Controller

I was wondering, why does the scaffolding for a resource use the model to identify something and how do I use that? I haven't found any online resources explaining this.

So the controller is scaffolded looking like

public function show(Model $model){
		// return Inertia::render
}

In order to get it to work thus far, i've had to change this to a string $id and pass that along with the route query. I'm using InertiaJS. I was wondering whether there was a faster way to show an individual instance of a model after clicking on it in an index.. It made sense to me that I could pass the object to the show, rather than having to reach out again for the model. Is that what this is built for? If so, I'm not sure how to pass the model's object on a router.get('') call on @click.

Feel free to ask for clarification. I'm really just looking for some basic documentation on how these resources are intended to be used so I can follow best practices.

0 likes
3 replies
rawfan's avatar
rawfan
Best Answer
Level 19

The scaffolding assumes you want to use route model binding. In that case you pass the id and your routes look someting like this:

Route::get('/model/{model}', [ModelController::class, 'show']);

If you now open /model/5 Laravel will automatically findOrFail that model and in the show method it will just be available as $model or you get a 404.

1 like
alexrobinson's avatar

@rawfan when I was visiting the /model/{} route I wasn't getting any information from a dd($model); call. Do you know why that would be?

alexrobinson's avatar

of course now it is returning something w/ dd(); no idea why though. It wasn't working before. Thanks!

Please or to participate in this conversation.