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;
相關文章
相關標籤/搜索