как вы получаете строку запроса в блейде laravel? - PullRequest
0 голосов
/ 13 января 2020

Я хочу спросить, как мне получить строку запроса, которую пользователь ввел в блейд? пример: 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>

Ответы [ 2 ]

1 голос
/ 13 января 2020
    <input type = "text" value = "{{!empty(app('request')->input('type')) ? app('request')->input('type') : '' }}">
    <input type = "text" value = "{{ !empty(app('request')->input('name')) ? app('request')->input('name') : '' }}">
1 голос
/ 13 января 2020

Вам нужно установить переменную, ваша строка запроса имеет значение по умолчанию:

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/>
...