How to set the access route in Laravel when the form is submitted?
阿神
阿神 2017-05-16 16:46:45
0
3
547

Form:

<form role="form" action='' method='GET'>
                    <input type="text"  placeholder="请输入赛事编码" name="race_num">
                    <button  type="submit">
                        查询
                    </button>
            </form>
            

routing:

Route::get('/', function () {
    return view('searchscor');
});

Route::get('/','SearchController@searchscor');

Writing like this will only access the second one. How to set routing so that after clicking the submit button (note: form action='' at this time), there is no need to transfer and access the current controller?

阿神
阿神

闭关修行中......

reply all(3)
给我你的怀抱

1.{{Request::path()}} Get the current route name in the template
2. You can also directly {{url('xxxx')}} on the action side, where xxxx is what you want to process Routing
3. If possible, remember to adopt it

我想大声告诉你

It doesn’t work if the request method and path of your two routes are the same. You can modify one of them.

Route::get('/search','SearchController@searchscor');

Then if you want to get the current routing address, you can use the following methods:

request()->url();
url()->current();
大家讲道理

Form:

<form role="form" action=' ' method='GET'>
                    <input type="text"  placeholder="请输入赛事编码" name="race_num">
                    <button  type="submit">
                        查询
                    </button>
 </form>

Route:
Route::get('/','SearchController@searchscor');
Controller:
public function searchscor(Request $request){

    $name=$request->input('race_num');
    return view('searchscore');
}

When action="", it means accessing the current route.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template