Ejemplo n.º 1
0
 public function expire($key, $expire = 0)
 {
     if ($expire > 0 && $this->has($key)) {
         $expire += time();
         $db = Db::instance('core', 'expire');
         $db->firstOrCreate(['key' => $key])->setExpire((int) $expire)->save();
     }
     return $this;
 }
Ejemplo n.º 2
0
 public static function __callStatic($method, $args)
 {
     $db = Inflector::uncamelize($method);
     if (fnmatch('*_*', $db)) {
         list($database, $table) = explode('_', $db, 2);
     } else {
         $database = SITE_NAME;
         $table = $db;
     }
     if (empty($args)) {
         return Db::instance($database, $table);
     } elseif (count($args) == 1) {
         $id = Arrays::first($args);
         if (is_numeric($id)) {
             return Db::instance($database, $table)->find($id);
         }
     }
 }
Ejemplo n.º 3
0
 public function __construct($ns)
 {
     $this->ns = $ns;
     $this->db = Db::instance('core', 'log');
 }
Ejemplo n.º 4
0
 public function pivot($model)
 {
     if ($model instanceof Db) {
         $model = $model->model();
     }
     $mTable = $model->db()->table;
     $names = [$this->_db->table, $mTable];
     asort($names);
     $pivot = Inflector::lower('pivot' . implode('', $names));
     return Db::instance($this->_db->db, $pivot);
 }
Ejemplo n.º 5
0
 public function fieldsRow()
 {
     $first = Db::instance($this->db, $this->table)->first(true);
     if ($first) {
         $fields = array_keys($first->assoc());
         unset($fields['id']);
         unset($fields['created_at']);
         unset($fields['updated_at']);
         unset($fields['deleted_at']);
         return $fields;
     } else {
         return [];
     }
 }