增加路由:
Route::any('Student/update/{id}',['uses'=>'StudentController@update']);
控制器代码:(Request $request不会影响参数)
public function update(Request $request,$id){
$student = Student::find($id);
if($request->isMethod('POST')){
//验证通过后继续进行
//方法2 Validator类验证
$validator = \Validator::make($request->input(),[
'Student.name' => 'required|min:2|max:20',
'Student.age' => 'required|integer',
'Student.gender' => 'required|integer',
],[
'required'=>':attribute 为必填项',
'min' => ':attribute 长度不符合要求',
'integer' => ':attribute 必须是一个整形',
],[ 'Student.name' => '姓名',
'Student.age' => '年龄',
'Student.gender' => '性别',
]);
if($validator->fails()){
return redirect()->back()->withErrors($validator)->withInput();
}
//如果验证通过,则继续执行下面的代码
$data = $request->input('Student');
$student->name = $data['name'];
$student->age = $data['age'];
$student->gender = $data['gender'];
if($student->save()){
return redirect('Student/index')->with('success','修改成功');
}else{
return redirect()->back();
}
}
return view('Student.update',[
'student'=>$student
]);
} 列表视图的代码:
<a href="{{ url('Student/update',['id'=>$val->id]) }}">编辑</a>

修改页面代码:
<form method="post" action="{{ url('Student/update',['id'=>$student->id]) }}">
{{ csrf_field() }}
姓名 :<input type="text" name="Student[name]" value="{{ old('Student')['name']?old('Student')['name']:$student->name }}" />
年龄 :<input type="text" name="Student[age]" value="{{ old('Student')['age']?old('Student')['name']:$student->age }}" />
性别 :
@foreach($student->user_sex() as $ind=>$val)
<input type="radio" name="Student[gender]" value="{{$ind}}" {{ (old('Student')['gender']?old('Student')['gender']:$student->gender)==$ind?'checked':'' }} />{{$val}}
@endforeach
<input type="hidden" name="Student[id]" value="{{$student->id}}">
<input type="submit" value="提交"/>
</form>
 


Laravel 修改操作的更多相关文章

  1. laravel 数据库操作(表、字段)

    1)创建表(make:migration create),例如创建 articles php artisan make:migration create_articles_table --create ...

  2. laravel基础操作手册

    laravel基础操作手册 1.路由配置 测试配置路由: Route::get('/test', 'TestController@index'); 2.控制器书写 3.模型文件 4.增加扩展类文件 L ...

  3. laravel修改用户模块的密码验证

    做项目的时候,用户认证几乎是必不可少的,如果我们的项目由于一些原因不得不使用 users 之外的用户表进行认证,那么就需要多做一点工作来完成这个功能. 现在假设我们只需要修改登录用户的表,表名和表结构 ...

  4. 关于SubSonic3.0插件使用实体进行更新操作时(执行T.Update()或T.Save()),某些列无法进行修改操作的问题处理

    SubSonic3.0插件在创建实体后,对实体进行赋值操作时,为了去除一些不必要更新的字段,减少更新的内容,会将更新内容与默认值进行比较,如果默认值与当前更新的内容相等时,则不提交更新本列,这主要是为 ...

  5. 采用DOM进行表格的修改操作

    2015-08-31 <html> <head> <title>采用DOM进行表格的修改操作</title> <script language=& ...

  6. uoj #58. 【WC2013】糖果公园(树上莫队算法+修改操作)

    [题目链接] http://uoj.ac/problem/58 [题意] 有一棵树,结点有自己的颜色,若干询问:u,v路径上的获益,并提供修改颜色的操作. 其中获益定义为Vc*W1+Vc*W2+…+V ...

  7. 基于jsp+servlet图书管理系统之后台用户信息修改操作

    上一篇的博客写的是查询操作,且附有源码和数据库,这篇博客写的是修改操作,附有从头至尾写的代码(详细的注释)和数据库! 此次修改操作的源码和数据库:http://download.csdn.net/de ...

  8. SpringDataJpa的批量 保存 修改 操作

    SpringDataJpa进行修改数据库操作有两种方式: 一.调用保存实体的方法 1.保存一个实体:repository.save(T entity) 2.保存多个实体:repository.save ...

  9. mysql常用快速查询修改操作

    mysql常用快速查询修改操作 一.查找并修改非innodb引擎为innodb引擎 # 通用操作 mysql> select concat('alter table ',table_schema ...

随机推荐

  1. PyCharm如何配置断点调试功能

    1. 点击菜单 PyCharm -> Preferences.. 2. 在左侧菜单栏找到Project:Django - > Project Interpreter 并点击配置 Proje ...

  2. VC-基础:隐藏不安全函数的warning-_CRT_SECURE_NO_WARNINGS

    >tmp.cpp(): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strc ...

  3. 51nod 1242 斐波那契数列的第N项——数学、矩阵快速幂

    普通算法肯定T了,所以怎么算呢?和矩阵有啥关系呢? 打数学符号太费时,就手写了: 所以求Fib(n)就是求矩阵  |  1  1  |n-1  第一行第一列的元素. |  1  0  | 其实学过线代 ...

  4. xadmin下设置“use_bootswatch = True”无效的解决办法

    环境: python 2.7 django 1.9 xadmin采用源代码的方式引入到项目中 问题: 在xadmin使用的过程中,设置“use_bootswatch = True”,企图调出主题菜单, ...

  5. 多线程并发情况下 重复insert问题

    代码逻辑: if(数据不存在){ insert(); } 线程启动后,发现数据库表中有相同的记录 解决方案 synchronized同步代码块即加同步锁,synchronized同步代码块的功能: 当 ...

  6. 1 producer — n consumers 模型 实现

    #include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> ...

  7. PowerShell-第2章 管道

    2.1 过滤列表项或命令输出项 列出所有正在运行进程名称中包含"search"的进程,对进程名字属性使用-like操作符来比较进程的Name属性 Get-Process | Whe ...

  8. java excutors 四种类型的线程

    http://blog.csdn.net/ochangwen/article/details/53044733

  9. Python内置函数5

    Python内置函数5 1.format参考前面字符串方法中的format 2.frozenset([iterable]) iterable -- 可迭代的对象,比如列表.字典.元组等等 返回一个冻结 ...

  10. C++枚举类型enum

    为啥需要枚举类型 编程语言中的所有特性都是为了满足某种需求,达到某个目的还出现.不会莫名其妙的出现在那. 枚举可以用来保存一组属性的值.enum的全称是enumeration意思是列举 看着这句话可能 ...