Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在blade laravel中获取查询字符串?_Laravel_Laravel 5_Eloquent - Fatal编程技术网

如何在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/>




谢谢,先生,这太神奇了,因为控制器中没有太多代码谢谢,先生,这太神奇了,因为控制器中没有太多代码