如何在blade laravel中获取查询字符串?
我想问一下如何获取用户输入到刀片的查询字符串? 例如:如何在blade laravel中获取查询字符串?,laravel,laravel-5,eloquent,Laravel,Laravel 5,Eloquent,我想问一下如何获取用户输入到刀片的查询字符串? 例如:localhost:8000/user/data/182?type=bank&name=bca 所以我的期望是,我将把查询字符串放入输入表单中 <input type = "text" value = "from query string type> <input type = "text" value = "from query string name> 您需要设置变量查询字符串为默认值: class Exampl
localhost:8000/user/data/182?type=bank&name=bca
所以我的期望是,我将把查询字符串放入输入表单中
<input type = "text" value = "from query string type>
<input type = "text" value = "from query string name>
您需要设置变量查询字符串为默认值:
class ExampleController
{
public function example() {
$query_string = [
'type' => null,
'name' => null,
]
// check request has query string and assign
if (request()->has('type')) {
$query_string['type'] = request()->get('type');
}
// check request has query string and assign
if (request()->has('name')) {
$query_string['name'] = request()->get('name');
}
return view('example', compact('query_string'));
}
}
并查看example.blade.php:
<form action="{{ route('example') }}" method="get" id="form1">
<input type = "text" value = {{ $query_string('type') }}>
<input type = "text" value = {{ $query_string('name') }}>
<form/>
您需要设置变量查询字符串为默认值:
class ExampleController
{
public function example() {
$query_string = [
'type' => null,
'name' => null,
]
// check request has query string and assign
if (request()->has('type')) {
$query_string['type'] = request()->get('type');
}
// check request has query string and assign
if (request()->has('name')) {
$query_string['name'] = request()->get('name');
}
return view('example', compact('query_string'));
}
}
并查看example.blade.php:
<form action="{{ route('example') }}" method="get" id="form1">
<input type = "text" value = {{ $query_string('type') }}>
<input type = "text" value = {{ $query_string('name') }}>
<form/>
谢谢,先生,这太神奇了,因为控制器中没有太多代码谢谢,先生,这太神奇了,因为控制器中没有太多代码