Laravel----隨記筆談
阿新 • • 發佈:2018-11-11
查詢時呼叫函式,小於0的數,自動補零;分組時,擷取欄位分組統計
$select = [ DB::RAW('SUBSTR(create_at,0,10) as sum_date'), DB::RAW("TO_CHAR(SUM(totalprice),'fm9999999990.00') as total_amount"),//小於1自動補零 DB::RAW("TO_CHAR(SUM(fee),'fm9999999990.00') as total_fee") ]; $data = OrderTemp::select($select)->where("is_income",2)->groupBy(DB::RAW('SUBSTR(create_at,0,10)'))->get();
查詢結果寫入一維陣列(原本二維陣列)
$terminal = Terminal::where('is_success', '!=', '1')->select('term_id')->get()->pluck('term_id')->toArray();
格式說明:
[
"00002001707120000001",
"0000200301AZ7A000005",
"0000200301AZ7A000011",
"0000200301AZ7A000022"
]
列印完整SQL
$params = $query->getBindings(); $sql = str_replace('?', '%s', $query->toSql()); $wholeSql = sprintf($sql,...$params); // 三個點不能少 dd($wholeSql);
上傳檔案基礎配置
if ($_FILES['pic']["error"] == 0){ $path = "./Public/image/advice/".date('Ymd',time()); $last_id = M('Advice')->order('id desc')->getField('id')+1; $last_id = $last_id?$last_id:1; if(!is_dir($path)){ mkdir($path,0777,true); chmod($path,0777); chown( $path,'daemon'); chgrp( $path,'daemon'); } $f = $path."/".time().$last_id.".png"; if($_FILES["pic"]['name'] != ''){ $data["pic"] = "http://".$_SERVER['HTTP_HOST'].$f; move_uploaded_file($_FILES["pic"]["tmp_name"],$_SERVER['DOCUMENT_ROOT'].$f); } }