laravel常用查詢

<?php
// 獲取request對象-控制器內獲取示列
public function search(Request $request)
{

}

// 函數獲取request對象
$request = request();

// 獲取請求參數
$request->input();//能獲取get, post參數, 及json形式參數
$request->get();//能獲取get, post參數, 不能獲取json形式參數

// 獲取IP
$request->ip();
$request->getClientIp();

// 擴展兩個php原生函數
ip2long();// ip轉數字
long2ip();// 數字轉ip




/*
* laravel框架寫原生sql示例
*/
 $likeKey = "%{$kwd}%";
 $res = DB::table('app_task as t')
            ->whereRaw('(t.is_out_time = ? and  (t.title like ? or t.content like ?))', [0, $likeKey,$likeKey])
            ->leftJoin('app_user as u','t.uid','=','u.id')
            ->paginate($num,['t.id','t.content','t.cate_id','t.top','u.nick','u.avatar','u.user_name'],'page',$page);






 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章