Laravel 表单发布到控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37612280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:56:11  来源:igfitidea点击:

Laravel form post to controller

phplaravelmodel-view-controller

提问by Kamran G.

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 I do in C# MVC.

我是 Laravel 的新手,无法将数据发布到控制器。我找不到相应的文档。我想在 Laravel 中做一些类似于我在 C# MVC 中所做的事情。

<form action="/someurl" method="post">
<input type="text" name="someName" />
<input type="submit">
</form>

Controller

控制器

[HttpPost]
public ActionResult SomeUrl(string someName)
{
...
}

回答by Sid

You should use route.

你应该使用路由。

your .html

您的 .html

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

in routes.php

routes.php

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

and finally in YourController.php

最后在 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; 
}