首页 > 解决方案 > 如何通过刀片文件中的url传递静态值?

问题描述

我想通过我的刀片文件中的 url 发送静态值。但这不起作用。你能给我解决方案吗

> 
> <a href="{{URL::to('/user-login')?rfq=1 }}">This is link</a>

标签: laravel

解决方案


你有语法错误,你可以通过

<a href="{{ URL::to('/user-login').'?rfq=1' }}">This is link</a>

这里?rfq=1这将在''这个标签下,因为它是字符串


因为您的路由器被定义为这样

Route::get('/user-login/{email}/{password}', 'UserController@user_login')->name('users.user_login');

您应该使用路由名称并像这样传递数据

<a href="{{ route('users.user_login',['email'=>'example@mail.com','password'=> '1234' ]) }}">This is link</a>

那么如果你需要通过,你可以像这样使用

<a href="{{ route('users.user_login',['email'=>'example@mail.com','password'=> '1234','rfq'=>1]) }}">This is link</a>

这将生成像localhost:8000/user-login/example@mail.com/1234?rfq=1" ref 链接https://laravel.com/docs/8.x/helpers#method-route这样的 url


推荐阅读