laravel_day5
程序员文章站
2022-03-16 08:18:54
...
一、PDO预处理
- laravel发送给mysql的语句 - toSql()
public function orwhere(){
// $res = DB::table('admin')->where('gid',0)->orWhere('ispasswd',1)->get(['id','username','real_name']);
$res = DB::table('admin')->where('gid',0)->orWhere('ispasswd',1)->toSql();
echo '<pre>';
print_r($res);
}
二、连表查询
- 原生查询
- 链式查询
// 连表查询
public function join(){
$res = DB::table('admin')->join('admin_group','admin.gid','=','admin_group.gid')->get();
echo '<pre>';
print_r($res);
}
三、中间件
- 中间件的创建
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Closure;
// 中间件
class Mycheck{
public function handle(Request $request,Closure $next){
$a = 3;
$b = 5;
echo 'a+b='.($a+$b);
return $next($request);
}
}
- 注册中间件
- 触发中间件
Route::get('/home/join','Home@join')->middleware('mycheck');
- 阻断中间件下面进程执行
// 中间件
class Mycheck{
public function handle(Request $request,Closure $next){
$a = 3;
$b = 5;
echo 'a+b='.($a+$b);
return response('aaa',200);
return $next($request);
}
}
推荐阅读