Laravel form post to controller

后端 未结 2 452
你的背包
你的背包 2020-12-12 05:06

I am new to Laravel and I\'m having trouble with posting data to a controller. I couldn\'t find the corresponding documentation. I want to something similar in Laravel that

相关标签:
2条回答
  • 2020-12-12 05:33

    This works best

    <form action="{{url('someurl')}}" method="post">
     @csrf
    <input type="text" name="someName" />
    <input type="submit">
    </form>
    
    

    in web.php

    Route::post('someurl', 'YourController@someMethod');
    
    

    and in your Controller

    public function someMethod(Request $request)
    {
       dd($request->all());  //to check all the datas dumped from the form
       //if your want to get single element,someName in this case
       $someName = $request->someName; 
    }
    
    
    0 讨论(0)
  • 2020-12-12 05:42

    You should use route.

    your .html

    <form action="{{url('someurl')}}" method="post">
    <input type="text" name="someName" />
    <input type="submit">
    </form>
    

    in routes.php

    Route::post('someurl', 'YourController@someMethod');
    

    and finally in YourController.php

    public function someMethod(Request $request)
    {
       dd($request->all());  //to check all the datas dumped from the form
       //if your want to get single element,someName in this case
       $someName = $request->someName; 
    }
    
    0 讨论(0)
提交回复
热议问题