コード例 #1
0
 public static function cacheTags(BasicModel $model)
 {
     $tags = array('QueryCache-table-' . $model->getTableName());
     if ($model->cache_tags) {
         $tags = array_merge($tags, $model->cache_tags);
     }
     return $tags;
 }
コード例 #2
0
 public static function queryRespondedToUserComments(BasicModel $user, $query = null)
 {
     $idArray = array();
     $comments = static::where(array('user_id' => $user->getKey()))->select(['id'])->get();
     foreach ($comments as $comment) {
         $idArray[] = $comment->id;
     }
     if ($query) {
         return $query->whereIn('commentable_id', $idArray)->where('commentable_type', get_called_class());
     } else {
         return static::whereIn('commentable_id', $idArray)->where('commentable_type', get_called_class());
     }
 }
コード例 #3
0
 public static function _schema(Blueprint $table)
 {
     $table = parent::_schema($table);
     $table->string('username', 100)->unique();
     $table->string('employee_id', 100)->unique();
     $table->string('email', 100)->unique();
     $table->string('mobile', 20)->unique();
     $table->string('avatar', 200)->nullable();
     $table->string('password', 100);
     $table->string('remember_token', 100);
     $table->timestamp('last_login');
     return $table;
 }
コード例 #4
0
 public static function create(array $attributes)
 {
     $attributes['parent_id'] = 1;
     return parent::create($attributes);
 }
コード例 #5
0
 public static function queryRelatedItemN(BasicModel $item_m, BasicModel $item_n)
 {
     $nTableName = $item_n->getTable();
     $lTableName = static::getTableName();
     $item_m->cache_tags = ['QueryCache-table-' . $lTableName];
     return $item_n->select($nTableName . '.*')->join($lTableName, function ($join) use($item_n, $item_m, $nTableName, $lTableName) {
         $m = static::$nameM;
         $n = static::$nameN;
         $join->on("{$lTableName}.{$n}_id", "=", "{$nTableName}." . $item_n->getKeyName())->where("{$lTableName}.{$m}_id", "=", $item_m->getKey())->where("{$lTableName}.{$n}_type", "=", $item_n->getMorphClass())->where("{$lTableName}.{$m}_type", "=", $item_m->getMorphClass());
     });
 }
コード例 #6
0
 public function save(array $options = array())
 {
     $user = parent::save($options);
     if (!empty($this->_profile)) {
         if (!$this->profile) {
             $profiles = $this->_profile;
             $profiles['user_id'] = $this->getKey();
             \ProfileModel::create($profiles);
         } else {
             foreach ($this->_profile as $key => $val) {
                 $this->profile->{$key} = $val;
             }
             $this->profile->save();
         }
         $this->_profile = array();
     }
     return $user;
 }