zl程序教程

您现在的位置是:首页 >  其他

当前栏目

laravel笔记

2023-04-18 14:47:18 时间

redis

$redisKey = "yixinzuqiu:houtai:column:getMatchListBySpecialColumn:{$userId}";
$data = Redis::connection('plan')->get($redisKey);
if ($data) {  
  $data = json_decode($data);
}else{
    Redis::connection('plan')->setex($redisKey, 60, json_encode($data));
}

//get
Redis::connection('plan')->get($redisKey)//setex
Redis::connection('plan')->setex($redisKey, 60, json_encode($data));
复制代码

Mysql

idArr 去重

$idArr = array_unique(array_column($data, 'id'));
$bUserList = (new BUserModel())->getListByDepartmentIdArr($idArr);
复制代码

打印最后一次执行的sql

DB::connection()->enableQueryLog();
var_dump(DB::getQueryLog());
die();


//whereor orwhere orwhereraw


if ($titlecontent = $this->request->get('titlecontent')){
            if (!$this->request->get('title')){
                $msg = $msg->where('title', 'like', '%' . $titlecontent . '%');
            }
            $msg = $msg->orWhereRaw('(content like ? and status = ?)', ["%{$titlecontent}%", 1]);
        }


 

//单个值


 $tmps['department_name'] = HoutaiDepartment::where('id', $tmp['department_id'])->first()['name'];



//事务
 DB::beginTransaction();
        try {
            $ht = BUserModel::where('id', $user_id)->update($data);
            if (HoutaiUserInfo::where('user_id', $user_id)->first())
                HoutaiUserInfo::where('user_id', $user_id)->update($params);
            else {
                $params['user_id'] = $user_id;
                HoutaiUserInfo::create($params);
            }
            DB::commit();
            return json_encode(['status' => 'success']);
        } catch (Exception $e) {
            DB::rollBack();
            return json_encode(['error' => '修改用户失败']);
        }



whereIn('id', $idArr)
            ->get();
        $data = [];

        if ($list) {
            $list = $list->toArray();
            foreach ($list as $value) {
                $data[$value['id']] = $value;
            }
        }

        return $data;
    }
}
复制代码

调整到另外一个路由

return route('FilePull', $arr);

Route::get('file', [

    'as' => 'FilePull',

    'alias' => '获取文件',

    'uses' => 'FileController@getFile'

]);
复制代码

删除和软删除

 Cases::find($id)->delete();

        Cases::destroy($id);

        //软删除恢复

//        Cases::find($id)->restore();
复制代码

永久删除模型

// 强制删除单个模型实例...

$flight->forceDelete();

// 强制删除所有关联模型...

$flight->history()->forceDelete();
复制代码

给参数默认值

$request->input('company_name',’sdfsaf’);
复制代码

服务器配置Nginx

try_files $uri $uri/ /index.php?$query_string;
复制代码