本文介紹了Laravel 表單發布到控制器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是 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;
}
這篇關于Laravel 表單發布到控制器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!