应该是view传参过去,然后模板文件说那个student变量未定义。查看有没有写错
把这三个方法放到外面,别用中间件。
要把方法定义为公共的函数不然不能继承使用
public function request(){ echo request()->input('name'); }
试试这个。
是访问的域不对吧
phpStorm
需要添加中间件
不错,找问题的能力可以呀
已经解决了,老师调用的是Student.name,我用的是Student['name'],似乎概念不太一样
没有添加验证 需要在添加之前加入验证
$validator=\Validator::make($request->input(),[ 'student.name'=>'required|min:2|max:10', 'student.age'=>'required|integer', 'student.sex'=>'required|integer' ],[ 'required'=>":attribute不能为空", 'integer'=>":attribute必须是整数", 'min'=>':attribute最小不能少于2字符' ],[ 'student.name'=>'姓名', 'student.age'=>'年龄', 'student.sex'=>'性别' ]); if($validator->fails()){ return redirect()->back()->withErrors($validator)->withInput(); }
请检查命名空间:
使用默认控制器验证使用方式: $this->validate($request,....)
使用验证类则需要加上命名空间: \Validator::make(), 斜杠命名空间+大写开头,另外要注意,使用数据验证,
是需要在路由到控制器之间设立一个中间件来进行过滤的,这时需要使用路由组来加载web中间件.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>表单</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <!-- 头部 --> <div class="jumbotron"> <div class="container"><h2>轻松学会Larvel</h2> <p>表单</p></div> </div><!-- 中间内容区域 --> <div class="container"> <div class="row"> <!-- 左侧菜单区域 --> <div class="col-md-3"> <div class="list-group"><a href="#" class="list-group-item active">学生列表</a> <a href="#" class="list-group-item">新增学生</a> </div> </div> <!-- 右侧内容区域 --> <div class="col-md-9"> <!-- 成功提示框 --> <div class="alert alert-success alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span> </button> <strong>成功!</strong><!-- 操作成功提示 --> </div> <!-- 失败提示框 --> <div class="alert alert-danger alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span> </button> <strong>失败!</strong><!-- 操作失败提示 --> </div> <div class="panel panel-default"> <div class="panel-heading">学生列表</div> <table class="table table-striped table-hover table-responsive"> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>添加时间</th> <th width="120">操作</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td><a href="">详情</a> <a href="">修改</a> <a href="">删除</a></td> </tr> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td><a href="">详情</a> <a href="">修改</a> <a href="">删除</a></td> </tr> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td><a href="">详情</a> <a href="">修改</a> <a href="">删除</a></td> </tr> </tbody> </table> </div> <!-- 分页 --> <div> <ul class="pagination pull-right"> <li><a href="#" aria-label="Previous"> <span aria-hidden="true">«</span> </a></li> <li class="active"><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li><a href="#" aria-label="Next"> <span aria-hidden="true">»</span> </a></li> </ul> </div> </div> </div> </div><!-- 尾部 --> <div class="jumbotron" style="margin: 0;"> <div class="container"><span> @2016 imooc </span></div> </div> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>表单</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <!-- 头部 --> <div class="jumbotron"> <div class="container"><h2>轻松学会Larvel</h2> <p>表单</p></div> </div><!-- 中间内容区域 --> <div class="container"> <div class="row"> <!-- 左侧菜单区域 --> <div class="col-md-3"> <div class="list-group"><a href="#" class="list-group-item active">学生列表</a> <a href="#" class="list-group-item">新增学生</a> </div> </div> <!-- 右侧内容区域 --> <div class="col-md-9"> <!-- 所有错误提示 --> <div class="alert alert-danger"> <ul> <li>姓名不能为空</li> <li>年龄只能为整数</li> <li>请选择性别</li> </ul> </div> <!-- 自定义内容区域 --> <div class="panel panel-default"> <div class="panel-heading">新增学生</div> <div class="panel-body"> <form class="form-horizontal"> <div class="form-group"><label for="name" class="col-sm-2 control-label">姓名</label> <div class="col-sm-5"><input type="text" class="form-control" id="name" placeholder="请输入学生姓名"></div> <div class="col-sm-5"><p class="form-control-static text-danger">姓名不能为空</p></div> </div> <div class="form-group"><label for="age" class="col-sm-2 control-label">年龄</label> <div class="col-sm-5"><input type="text" class="form-control" id="age" placeholder="请输入学生年龄"></div> <div class="col-sm-5"><p class="form-control-static text-danger">年龄只能为整数</p></div> </div> <div class="form-group"><label for="sex" class="col-sm-2 control-label">性别</label> <div class="col-sm-5"><label class="radio-inline"> <input type="radio" name="sex" value="option1"> 未知 </label> <label class="radio-inline"> <input type="radio" name="sex" value="option2"> 男 </label> <label class="radio-inline"> <input type="radio" name="sex" value="option3"> 女 </label> </div> <div class="col-sm-5"><p class="form-control-static text-danger">请选择性别</p></div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-primary">提交</button> </div> </div> </form> </div> </div> </div> </div> </div><!-- 尾部 --> <div class="jumbotron" style="margin: 0;"> <div class="container"><span> @2016 imooc </span></div> </div> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>表单</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <!-- 头部 --> <div class="jumbotron"> <div class="container"><h2>轻松学会Larvel</h2> <p>表单</p></div> </div><!-- 中间内容区域 --> <div class="container"> <div class="row"> <!-- 左侧菜单区域 --> <div class="col-md-3"> <div class="list-group"><a href="#" class="list-group-item active">学生列表</a> <a href="#" class="list-group-item">新增学生</a> </div> </div> <!-- 右侧内容区域 --> <div class="col-md-9"> <!-- 自定义内容区域 --> <div class="panel panel-default"> <div class="panel-heading">学生详情</div> <table class="table table-bordered table-striped table-hover"> <tbody> <tr> <td width="50%">ID</td> <td>1</td> </tr> <tr> <td>姓名</td> <td>sean</td> </tr> <tr> <td>年龄</td> <td>18</td> </tr> <tr> <td>性别</td> <td>男</td> </tr> <tr> <td>添加日期</td> <td>2016-01-01</td> </tr> <tr> <td>最后修改</td> <td>2016-03-01</td> </tr> </tbody> </table> </div> </div> </div> </div><!-- 尾部 --> <div class="jumbotron" style="margin: 0;"> <div class="container"><span> @2016 imooc </span></div> </div> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </body> </html>
先有布局然后再有的内容呀
dd($response);
请问如何解决的
//json返回
return json_encode(['code'=>-1,'message'=>$errStr]);
//使用框架json返回
return response()->json(['code' => -1,'message'=>$errStr]);
public $timestamps = ture 修改为 public $timestamps = true 或者你直接删除 public $timestamps = ture
你模型里应该没有定义$fillable
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>表单</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"></head><body> <!-- 头部 --><div class="jumbotron"> <div class="container"> <h2>轻松学会Larvel</h2> <p>表单</p> </div></div><!-- 中间内容区域 --><div class="container"> <div class="row"> <!-- 左侧菜单区域 --> <div class="col-md-3"> <div class="list-group"> <a href="#" class="list-group-item active">学生列表</a> <a href="#" class="list-group-item">新增学生</a> </div> </div> <!-- 右侧内容区域 --> <div class="col-md-9"> <!-- 成功提示框 --> <div class="alert alert-success alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> <strong>成功!</strong><!-- 操作成功提示 --> </div> <!-- 失败提示框 --> <div class="alert alert-danger alert-dismissible"> <button type="buttn" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> <strong>失败!</strong><!-- 操作失败提示 --> </div> <div class="panel panel-default"> <div class="panel-heading">学生列表</div> <table class="table table-striped table-hover table-responsive"> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>添加时间</th> <th width="120">操作</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td> <a href="">详情</a> <a href="">修改</a> <a href="">删除</a> </td> </tr> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td> <a href="">详情</a> <a href="">修改</a> <a href="">删除</a> </td> </tr> <tr> <th scope="row">1</th> <td>Mark</td> <td>18</td> <td>男</td> <td>2016-01-01</td> <td> <a href="">详情</a> <a href="">修改</a> <a href="">删除</a> </td> </tr> </tbody> </table> </div> <!-- 分页 --> <div> <ul class="pagination pull-right"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li class="active"><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </div> </div> </div></div><!-- 尾部 --><div class="jumbotron" style="margin: 0;"> <div class="container"> <span> @2016 imooc </span> </div></div><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script></body></html>
我碰到过类似的问题,但我是这么解决的。我估摸着自己是否是在路由文件里多打了个什么,所以复制了一份原框架的路由就好了。你也可以试试 框架里的路由文件和kerenl.php重新复制到自己的项目中
执行了web中间键才可以session_start()
jQuery百度一下直接下载啊。我再 http://www.jq22.com/ 这里下载的!打开后页面最上边有jQuery下载