美文网首页
Larave Insert方法黑白名单时间维护

Larave Insert方法黑白名单时间维护

作者: trepeng | 来源:发表于2017-09-20 10:55 被阅读0次

    添加自己ORM基类中

        public function create(array $param)
        {
            if ($this->model->getName('timestamps')) {
                $time = time();
                $date = date('Y-m-d H:i:s', $time);
                $param['updated_at'] = $date;
                $param['created_at'] = $date;
            }
    
            if (! empty($this->model->getName('guarded')) && ($this->model->getName('guarded')[0] == '*')) {
                $fillable = $this->model->getName('fillable');
    
                foreach ($param as $key => $val) {
                    if (! in_array($key, $fillable)) {
                        unset($param[$key]);
                    }
                }
            } else {
                $fillable = $this->model->getName('guarded');
    
                foreach ($param as $key => $val) {
                    if (in_array($key, $fillable)) {
                        unset($param[$key]);
                    }
                }
            }
    
            return $this->model->insert($param);
        }
    

    相关文章

      网友评论

          本文标题:Larave Insert方法黑白名单时间维护

          本文链接:https://www.haomeiwen.com/subject/jginsxtx.html