我是Laravel的新手,我在将数据发布到控制器时遇到了麻烦。我找不到相应的文档。我希望在Laravel中有类似的东西,我在C#MVC中做的事情。
<form action="/someurl" method="post">
<input type="text" name="someName" />
<input type="submit">
</form>
控制器
[HttpPost]
public ActionResult SomeUrl(string someName)
{
...
}
答案 0 :(得分:7)
你应该使用路线。
您的.html
<form action="{{url('someurl')}}" method="post">
<input type="text" name="someName" />
<input type="submit">
</form>
routes.php
中的
Route::post('someurl', 'YourController@someMethod');
最后在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;
}
答案 1 :(得分:2)
效果最好
<form action="{{url('someurl')}}" method="post">
@csrf
<input type="text" name="someName" />
<input type="submit">
</form>
在web.php
Route::post('someurl', 'YourController@someMethod');
并在您的控制器中
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;
}