Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:作业有点不走心呀, 下次多写点
配置路由
Route::get('test','Test@querys');
Route::get('test/update','Test@updates');
Route::get('test/inserts','Test@inserts');
Route::get('test/del','Test@del');
控制器test.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class Test extends Controller
{
public function querys()
{
// $res['datalist'] =DB::select("select * from user");
// $res['datalist']= DB::table('user')->get()->all();
// 条件查询
// $res['datalist']= DB::select('select * from user where uid = :id', ['id' => 2]);
$res['datalist'] = DB::table('user')->where(['uid' => 2])->get();
return view("querys", $res);
}
public function updates()
{
// 原生更新操作
// $res=DB::update('update user set email = :e where uid=:id',['e'=>'5689@qq.com','id'=>3]);
$res = DB::table('user')->where(['uid' => 1])->update(['email' => 'df688@163.com']);
var_dump($res);
}
public function inserts(){
// 增加操作
// $res=DB::insert('insert user set username=:n, email = :e ',['n'=>'sam','e'=>'kkk@hotmail.com']);
$res=DB::table('user')->insert(['username'=>'小白','email'=>'s33@qq.com']);
var_dump($res);
}
public function del(){
// $res=DB::delete("delete from user where uid=:id",['id'=>5]);
$res=DB::table('user')->where(['uid'=>4])->delete();
var_dump($res);
}
}