Lumen快速入门

来源:https://notestore.cn/laravel-...laravel

DB类

use Illuminate\Support\Facades\DB;
读取数据库 0~20 条数据
DB::table("?")->where('字段名', 条件值)->where('字段名',条件值)->where('字段名',条件值)->whereIn('字段名',[1,2])->orderBy('字段名','ASC')->select('字段名1','字段名2','字段名3','字段名4')->groupBy('字段名')->skip(0)->take(20)->get();
添加数据
DB::table('?')->insert(["字段名" => 字段值,"字段名" => 字段值]);
更新数据
DB::table('?')->where(["字段名" => 字段值,"字段名" => 字段值])->update(["字段名" => 字段值,"字段名" => 字段值]);
详情查询
DB::table('?')->where(['字段名' => 字段值,'字段名' => 字段值,'字段名' => 字段值,'字段名' => 字段值])->first(['字段名1','字段名2']);
添加返回id
DB::table('?')->insertGetId(["字段名" => 字段值,"字段名" => 字段值]);
join查询
DB::table('?1')->whereIn('?1.字段名',[值,值])->where([['?1.字段名','<>',值],['?1.字段名','=',字段值],['?1.字段名','=',字段值]])->where(function ($query) {
                $query->where('?2.status','=',字段值)->orWhere('?1.字段名','=','字段值');
            })->where(function ($query) use (变量值) {
              $query->where('?2.字段名','like',变量值. '%')->orWhere('?1.字段名', 'like','%' . 变量值. '%')->orWhere('?3.字段名', 'like',变量值. '%');
          })->leftJoin('?2','?2.字段名', '=', '?1.字段名')->leftJoin('?3','?3.字段名', '=', '?1.字段名')->orderBy('?2.字段名','ASC')->orderBy('?2.字段名','ASC')->orderBy('?3.字段名','ASC')->select('?1.字段名','?2.字段名','?2.字段名','?1.字段名','?1.字段名 as 字段名')->groupBy('?1.字段名')->skip(0)->take(20)
            ->get();

Request类

use Illuminate\Http\Request;
读取 url 中参数
$language = $request->get('language');

Cache类

use Illuminate\Support\Facades\Cache;
检测是否有缓存
Cache::has("缓存名")
获取缓存数据
Cache::get("缓存名");
写入缓存,永久有效
Cache::forever("缓存名","缓存值");
清除缓存
Cache::forget("缓存名");
写入缓存,设置过时时间
Cache::put("缓存名","缓存值",Carbon::parse(date("Y-m-d H:i:s",过时时间戳)));

Crypt类

use Illuminate\Support\Facades\Crypt;
解密
Crypt::decrypt(待解密内容);
加密
Crypt::encrypt(待加密内容);

Carbon类

use Illuminate\Support\Carbon;
相关文章
相关标签/搜索