laravel框架 composer安装 及简单的增、删、改、查(分页)
来源:互联网 发布:iphone7plus在线软件 编辑:程序博客网 时间:2024/05/01 14:50
在运行窗口中(cmd)进入到站点文件下 首先运行下 composer
之后输入命令
composer create-project laravel/laravel --prefer-dist my_laravel
等待下载安装 就可以了
控制器 Test2Controller.php
<?php
namespace App\Http\Controllers;
use DB;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
class Test2Controller extends Controller{
//表单
public function getIndex(){
return view('index');
}
//添加
public function postAdd(Request $request){
$data = $request->input();
$res = DB::table('users')->insert($data);
if($res){
return redirect('show');
}else{
return redirect('index');
}
}
//分页展示
public function getShow(){
$users = DB::table('users')->paginate(5);
return view('show', ['users' => $users]);
// return view('show',array("users"=>$users));
}
//删除
public function getDel(Request $request){
$id = $request->input("id");
// var_dump($id);
$res = DB::table('users')->where('id', '=', $id)->delete();
if($res){
return redirect('show');
}else{
return redirect('show');
}
}
//修改(页面展示)
public function getSave(Request $request){
$id = $request->input("id");
$arr = DB::table('users')->where('id', $id)->first();
// var_dump($arr);die;
return view('save',array("arr"=>$arr));
}
//修改(数据处理)
public function postSaved(Request $request){
$list = $request->input();
// var_dump($list);die;
$res = DB::table('users')->where('id', $list['id'])->update($list);
if($res){
return redirect('show');
}else{
return redirect('show');
}
}
}
表单index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="add" method="post">
<table>
<tr>
<td>姓名:</td>
<td><input type="text" name='name' value=""></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" name='sex' value='男' checked="checked">男
<input type="radio" name='sex' value='女'>女
</td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name='age' value=""></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
展示 show.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" class='table'>
<th>编号</th>
<th>名字</th>
<th>性别</th>
<th>年龄</th>
<th>操作</th>
<?php foreach($users as $k=>$v){ ?>
<tr>
<td><?php echo $v['id']?></td>
<td><?php echo $v['name']?></td>
<td><?php echo $v['sex']?></td>
<td><?php echo $v['age']?></td>
<td>
<a href="save?id=<?php echo $v['id']?>">修改</a>
<a href="del?id=<?php echo $v['id']?>">删除</a>
</td>
</tr>
<?php }?>
</table>
<?php echo $users->links() ?>
</body>
</html>
修改页面 save.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="saved" method="post">
<input type="hidden" name="id" value="<?php echo $arr['id']?>">
<table>
<tr>
<td>姓名:</td>
<td><input type="text" name='name' value="<?php echo $arr['name']?>"></td>
</tr>
<tr>
<td>性别:</td>
<td>
<?php if($arr['sex']=="男"){ ?>
<input type="radio" name='sex' value='男' checked="checked">男
<input type="radio" name='sex' value='女'>女
<?php }else{ ?>
<input type="radio" name='sex' value='男'>男
<input type="radio" name='sex' value='女' checked="checked">女
<?php }?>
</td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name='age' value="<?php echo $arr['age']?>"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
- laravel框架 composer安装 及简单的增、删、改、查(分页)
- yii框架 简单的增、删、改、查(分页)
- composer安装及使用composer安装laravel框架
- composer安装laravel框架
- composer安装 laravel 框架
- composer安装laravel框架
- composer 安装laravel 框架
- composer 安装laravel 框架
- composer 安装laravel 框架
- composer安装laravel框架
- composer 安装laravel 框架
- laravel框架的增删改查
- Linux下composer及laravel的安装
- 使用 Composer 安装 Laravel 框架
- 用Composer 安装 laravel框架
- 使用composer安装laravel框架
- 用Composer 安装 laravel框架
- thinkphp(3.2)及laravel(5.4)框架的增删改查总结
- 使用AccessibilityService带你自动安装软件以及自动添加微信好友
- java对象json字符串互转
- CAD二次开发 选择集使用
- Java线程阻塞与中断
- Android--点击视图外部,隐藏键盘
- laravel框架 composer安装 及简单的增、删、改、查(分页)
- flash摄像头的使用
- Python自学之计算
- Linux下C语言学习之路——(0)学习路线的选择
- Java线程间的通信
- 两张图片相似度比较
- Python自学之String
- Pojo
- 在navicat for mysql中建立触发器