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

Oggy's avatar
Level 1

Route::view dynamically not working

After doing something like this:

Route::view('/video/{id}', 'overlays/video', ['id' => $id]);

it throws: Undefined variable: id

It is intended to work only like this:

Route::view('/video', 'overlays/video', ['id' => 'my_id']);

or there is a way to send that variable like I tried but I'm doing something wrong?

0 likes
5 replies
Oggy's avatar
Level 1

First time I have tried Route::view('/video/{id}', 'overlays/video', compact('id')]); with same error and thought it could be because of compact() function...

Oggy's avatar
Level 1

I came with a solution like this: Route::get('/video/{id}', function($id){return view('overlays/video', compact('id'));}); but... meh, its not a new way to do it...

Oggy's avatar
Level 1

Today discovered that even this, won't work: Route::view('/ip', 'ip', ['ip' => $_SERVER['REMOTE_ADDR']]);

J_shelfwood's avatar

It is recommended to use controllers and such, they provide much more features.

Oggy's avatar
Level 1

Yes they do, but what if the only thing you need is to return a view and User IP or load an Overlay with video ID through Ajax request? Then its like Laravel provide a very awesome new feature but its incomplete.

Please or to participate in this conversation.