如何在Laravel中生成网址

问题描述 投票:-1回答:1

路线看起来像:

Route::get('/data/', 'TesData@data');
Route::get('/data/{data_rahasia}', 'TesData@data_proses');

Web浏览器:

enter image description here

enter image description here

我的问题是,我们如何生成动态网址。就像youtube一样,如果我们单击视频项目,它们会生成:https://www.youtube.com/watch?v=N75eELx6eo0

php laravel url url-routing
1个回答
0
投票

如果您的URL没有任何参数,则可以使用此参数生成

route('your_route_name'); 
// Output: http://example.com/your-route-here

如果您的路由具有诸如以下参数:

Route::get('/data/{data_rahasia}', 'TesData@data_proses')->name('test-route');
...
// you can generate this routeby passing an array  in `route` helper where keys are parameter names and values are values:
route('test-route', ['data_rahasia' => 'some_value']);
// Output: http://example.com//data/some_value

此外,如果您的路由没有参数,并且在route帮助程序中传递了参数,它将生成url,其中传递的参数将位于url中

route('some-route', ['param1' => 22, 'param2' => 23])
// output: http://example.com/some-route?param1=22&param2=23

希望这对您有所帮助。另请参见:Laravel Routing Documentation

© www.soinside.com 2019 - 2024. All rights reserved.