search

Home  >  Q&A  >  body text

How to set the access route in Laravel when the form is submitted?

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?

阿神阿神2757 days ago528

reply all(3)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 16:48:45

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:48:45

    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();

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-16 16:48:45

    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.

    reply
    0
  • Cancelreply