当前,当我的页面之一加载时,我能够将数据写入mysql。这是我的控制器中的代码。
public function manuelSignUP()
{
DB :: table("users") -> insertGetId
(
array("firstname" => "John", "lastname"=> "John",
"passwordHash" => "password", "userslevelID" => 2)
);
DB :: table("userlevel") -> insertGetID
(
array("userlevelID" => $userlevelID, "name" => $name)
);
return view("pages.manualsignup");
}
因此,我想在单击按钮时通过刀片文件调用此函数,但是我一直在努力做到这一点。这是带有按钮的我的刀片文件。
<!DOCTYPE html>
<html>
<head> </head>
<body> This should </body>
<br><br><br><br>
<form method="post">
<button type="button"> submit </button>
</form>
</html>
基于谷歌搜索,我知道我可以使用ajax来解决这个问题,但是我相信有一种方法可以只使用html post方法。我正在尝试第二种方式,而没有ajax。
如果您不使用ajax,则需要指定该action
属性应与表单一起放置的位置,method
仅凭此属性是不够的。
看法
<form action="{{ route('signup') }}" method="post">
<button type="submit"> submit </button>
</form>
routes.php
Route::post('/signup', [
'as' => 'signup',
'uses' => 'YourController@manuelSignUP',
]);
同样,通常您应该使用表格将数据输入到其中,而不是对其进行硬编码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句