laravel框架学习记录之表单操作详解(3)

当验证失败返回到表单页面后,用户原来的输入信息会消失,这样需要再填一遍,可以通过old方法显示用户原来的输入

<input type="text" name="Student[name]" value="{{old('Student')['name']}}" >

5、错误记录

①、 MethodNotAllowedHttpException No message

这个错误是因为我把表单的post请求发送到了Route::get()定义的路由上,它不会处理post请求,可以把路由通过Route::Match(['get','post'],)来定义

②、Action App\Http\Controllers\StudentController@delete not defined

这个错误发生在我将在blade页面请求跳转到一个action,无法找到该Controller

<a href="{{action('StudentController@delete',['id'=>$student->id])}}" rel="external nofollow" >删除</a>

但当我在routes/web.php下注册了该方法后报错消失

Route::get('delete/{id}','StudentController@delete');

③、The page has expired due to inactivity. Please refresh and try again.

这是由于laravel自动设置了防止CSRF跨域攻击,你需要在表单内添加csrf_filed()来告诉laravel请求的发起人与表单提交者是同一个人。

<form class="form-horizontal" method="post" action="{{url('student/create')}}">
  {{ csrf_field() }}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。