Php 提交表单时在laravel中路由
我刚开始学拉威尔。我能够从mysql表中获取数据,但无法发布数据。我对定义post url的路径感到困惑 模型:Entry.phpPhp 提交表单时在laravel中路由,php,mysql,laravel,Php,Mysql,Laravel,我刚开始学拉威尔。我能够从mysql表中获取数据,但无法发布数据。我对定义post url的路径感到困惑 模型:Entry.php 视图:entry.blade.php 在主页上,我可以轻松地从数据库中提取记录,但当我尝试发布新记录时,它会显示错误 Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 当您使用blade时,您可以开始使用blade syntaxis,这将使创建表单更加容易 {{ Form:
视图:entry.blade.php
在主页上,我可以轻松地从数据库中提取记录,但当我尝试发布新记录时,它会显示错误
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
当您使用blade时,您可以开始使用blade syntaxis,这将使创建表单更加容易
{{ Form::open(array('url' => 'submit')) }}
// The 'url' => 'submit' wil refer to your route and fetch your postFunction you made.
// You can here setup your form components...
{{ Form::close() }}
创建组件的参考:
注:
检查控制器中的输入时,不要忘记使用Laravel验证器。
<HTML>
<HEAD>
<TITLE>Laravel Guestbook</TITLE>
</HEAD>
<BODY>
@foreach($entries as $entry)
<p>{{ $entry->comment }}</p>
<p>Posted on {{ $entry->created_at }} by
<a href="mailto:{{ $entry->email }}">{{ $entry->username}}</a>
</p><hr />
@endforeach
<form action="submit/" method="POST">
<table border="0">
<tr>
<td>Name</td>
<td><input type="text" name="frmName" value="" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="frmEmail" value="" size="30" maxlength="100"></td>
</tr>
<tr>
<td>Comment</td>
<td><textarea name="frmComment" rows="5" cols="30"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="submit">
<input type="reset" name="reset" value="reset"></td>
</tr>
</table>
</form>
</BODY>
</HTML>
Route::get('/', 'EntriesController@getIndex');
Route::get('submit', 'EntriesController@postIndex');
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
{{ Form::open(array('url' => 'submit')) }}
// The 'url' => 'submit' wil refer to your route and fetch your postFunction you made.
// You can here setup your form components...
{{ Form::close() }}