如何通过URL在Laravel中传递布尔值?

发布于 2025-02-05 04:52:04 字数 218 浏览 1 评论 0原文

我需要传递像“

Route::get('/link/page', 'TestController@index')->defaults('_config', [
            'view' => 'test::home.page.index'
        ])->name('test.home.page.index');

I need to pass a param like "link/page?url=true" or "link/page?url=false"

How can I set it in my route file?

Route::get('/link/page', 'TestController@index')->defaults('_config', [
            'view' => 'test::home.page.index'
        ])->name('test.home.page.index');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2025-02-12 04:52:05

如果参数将是一个查询参数,则无需在路由文件中定义它。在控制器中,您可以获取参数:

$request->query('url');

但是,如果您真的希望参数作为URL本身的一部分,那么您可以这样定义它:

Route::get('/link/page/{url}', 'TestController@index')

要在控制器中获取它,您必须执行此操作:

TestController {
     public function index($url){
          //put your logic.
     }
}

If the param is going to be a query parameter, then there is no need to define it in the Route file. In the controller you can fetch the param as:

$request->query('url');

But if you really want the parameter to part of the URL itself then you can define it like this:

Route::get('/link/page/{url}', 'TestController@index')

and to fetch it in controller you have to do this:

TestController {
     public function index($url){
          //put your logic.
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文