Esempio n. 1
0
 /**
  * Execute the query as a "select" statement.
  *
  * @param  array                                             $columns
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function get($columns = array('*'))
 {
     if ($this->is_collection) {
         $this->query->setModel(new Collection(array('table_name' => $this->name)));
     } elseif ($this->query instanceof \Illuminate\Database\Query\Builder) {
         $this->query->from($this->name);
     }
     // Check 'read' access before running the query.
     // - for 'owner' role each entry need to be checked on results.
     $role = Role::getInstance()->getConfig($this->name, 'read');
     if ($role !== 'owner' && !Role::isAllowed($this->name, 'read')) {
         throw new ForbiddenException();
     }
     return $this->__call('get', func_get_args());
 }
Esempio n. 2
0
 /**
  * Scope for the last conversations orderd by last message.
  *
  * ToDo: Optimize with join
  *
  * @param Illuminate\Database\Query\Builder $query
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeConversations($query)
 {
     return $query->from(\DB::raw('(select * from `messages` order by `created_at` desc) as `messages`'))->groupBy('message_conversation_id');
 }