Laravel 表单发布到控制器

2021-12-21 00:00:00 php laravel model-view-controller

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

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.

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

控制器

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

推荐答案

你应该使用路由.

你的.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; 
}

相关文章