/**
  * Check Existing Data
  *
  * @return void
  * @author 
  **/
 public static function checkData($table = NULL)
 {
     $existTable = DB::query("show tables like '" . Content::$table . "'");
     if (empty($existTable)) {
         return false;
     }
     $table = $table != NULL ? $table : Content::$table;
     $count = DB::table($table)->count();
     return $count > 0 ? true : false;
 }
 /**
  * Get the user from the database table.
  *
  * @param  array  $arguments
  * @return mixed
  */
 protected function get_user($arguments)
 {
     $table = Config::get('auth.table');
     return DB::table($table)->where(function ($query) use($arguments) {
         $username = Config::get('auth.username');
         $query->where($username, '=', $arguments['username']);
         foreach (array_except($arguments, array('username', 'password', 'remember')) as $column => $val) {
             $query->where($column, '=', $val);
         }
     })->first();
 }
Exemple #3
0
 /**
  * Seed the database from the given path.
  *
  * @param array   $arguments
  * @return int
  */
 public function seed($arguments = array())
 {
     $total = 0;
     foreach ($this->globSeedFiles() as $file) {
         $records = $this->loadSeedFile($file);
         // We'll grab the table name here, which could either come from the array or
         // from the filename itself. Then, we will simply insert the records into
         // the databases.
         $table = $this->fetchTableName($records, $file);
         Database::table($table)->delete();
         Database::table($table)->insert($records);
         $total += $count = count($records);
         echo sprintf("Seeded: `%s` (%d rows)\n", $table, $count);
     }
     return $total;
 }
 /**
  * Get the user from the database table by username.
  *
  * @param  mixed  $value
  * @return mixed
  */
 protected function get_user($value)
 {
     $table = Config::get('auth.table');
     $username = Config::get('auth.username');
     return DB::table($table)->where($username, '=', $value)->first();
 }
 /**
  * Drop the pre-migration schema for the current migration.
  *
  * @return void
  */
 protected function delete_schema()
 {
     DB::table('laravel_schema')->where('name', '=', get_class($this))->delete();
 }
Exemple #6
0
 /**
  * Gets the users' ids from which the current user has unread messages from
  * @return int[] Array with the users' IDs
  */
 public static function getUnreadUsers()
 {
     $myId = \Auth::user()->id;
     // Get all unread messages directed to me
     $messages = DB::table('messages')->where('status', '=', 'false')->where(function ($query) use($myId) {
         $query->or_where('to', '=', $myId);
     })->get();
     $users = array();
     foreach ($messages as $message) {
         $users[] = $message->from;
         // $users['nick'] = $message->nick;
     }
     return array_unique($users);
 }
Exemple #7
0
 public function find($id)
 {
     $column = 'id';
     if (!is_numeric($id)) {
         if (is_null($this->slug)) {
             $this->code = 404;
             $this->data = 'You are trying to retrieve data with a slug from a resource that is not retrievable via a slug';
             return false;
         }
         if ($this->multilanguage) {
             $language_row = DB::table($this->language_table)->where_slug($id)->first(array($this->language_table_foreign_key, 'language_id'));
             if (is_null($language_row)) {
                 $id = null;
             } else {
                 $id = $language_row->{$this->language_table_foreign_key};
                 $this->options(array('filter' => array('language_id' => $language_row->language_id)));
             }
         } else {
             $column = 'slug';
         }
     } elseif ($this->parent && $this->parent->multilanguage) {
         if (!$this->input['language_id']) {
             $this->code = 404;
             $this->data = 'Please provide the language_id';
             return false;
         }
         $this->language_id = $this->input['language_id'];
         $this->model = $this->model->where($this->table . '.language_id', '=', $this->input['language_id']);
         $column = $this->parent->language_table_foreign_key;
     }
     $this->id = $id;
     $this->model = $this->model->where($this->table . '.' . $column, '=', $id);
     if (is_null($this->model->first())) {
         $this->code = 404;
         $this->data = 'The data you are trying to retrieve could not be found';
         return false;
     }
     return true;
 }