title: How to select users except roles with Laravel Eloquent
body: <p>I need to select only id and name attribute from users table except roles attribute. I tried this:</p>
  
  <pre><code>$school_user = User::select('name', 'id')-&gt;get()-&gt;toArray();
  </code></pre>
  
  <p>but when I print it to screen it returns array with his roles. Like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [name] =&gt; Admin
              [id] =&gt; 1
              [roles] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [id] =&gt; 3
                              [name] =&gt; admin
                              [pivot] =&gt; Array
                                  (
                                      [user_id] =&gt; 1
                                      [role_id] =&gt; 1
                                  )
  
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>Any suggestions to get only name and id attributes except roles?</p>
  
  <p>There is my User Model class (a bit cleaned):</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Auth\UserTrait;
  use Illuminate\Auth\UserInterface;
  use Illuminate\Auth\Reminders\RemindableTrait;
  use Illuminate\Auth\Reminders\RemindableInterface;
  
  class User extends Eloquent implements UserInterface, RemindableInterface {
  
      use UserTrait, RemindableTrait;
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'users';
  
      /**
       * The attributes excluded from the model's JSON form.
       *
       * @var array
       */
      protected $hidden = array('password', 'remember_token');
  
      protected $fillable = array('email', 'name', 'password', 'block');
      protected $guarded = array('id');
  
      /**
       * Get the schools or kindergardens a user can moderate
       */
      public function schools()
      {
          return $this-&gt;belongsToMany('School', 'school_user');
      }
  
      /**
       * Get the roles a user has
       */
      public function roles()
      {
          return $this-&gt;belongsToMany('Role', 'users_roles');
      }
  
      /**
       * Find out if User is an employee, based on if has any roles
       *
       * @return boolean
       */
      public function isEmployee()
      {
          $roles = $this-&gt;roles-&gt;toArray();
          return !empty($roles);
      }
  
      /**
       * Find out if user has a specific role
       *
       * $return boolean
       */
      public function hasRole($check)
      {
          return in_array($check, array_fetch($this-&gt;roles-&gt;toArray(), 'name'));
      }
  
      /**
       * Get key in array with corresponding value
       *
       * @return int
       */
      private function getIdInArray($array, $term)
      {
          foreach ($array as $key =&gt; $value) {
              if ($value['name'] == $term) {
                  return $key;
              }
          }
  
          throw new UnexpectedValueException;
      }
  
      /**
       * Add roles to user to make them a concierge
       */
      public function makeEmployee($role_id)
      {
          $assigned_roles = array();
  
          $roles = Role::all()-&gt;keyBy('id')-&gt;toArray();
  
          $this-&gt;roles()-&gt;attach(array($role_id));
      }
  
      public $invitation;
  
      protected static function boot()
      {
          parent::boot();
  
          static::creating(function($model)
          {
              $data = array(
                  'invitation' =&gt; $model-&gt;invitation,
                  'email' =&gt; $model-&gt;email,
                  'name' =&gt; $model-&gt;name,
                  'password' =&gt; $model-&gt;password
              );
  
              $model-&gt;password = Hash::make($model-&gt;password);
  
              $rules = array(
                  'invitation' =&gt; 'required',
                  'email' =&gt; 'unique:users,email|required|email',
                  'name' =&gt; 'required|min:3|max:20',
                  'password' =&gt; 'required|min:8|max:30'
              );
              $validator = Validator::make($data, $rules);
  
              if ($validator-&gt;fails()) {
                  throw new ValidationException(null, null, null, $validator-&gt;messages());
              } else {                
                  return $model-&gt;validate();
              }
          });
  
          static::created(function($model)
          {
              $role_id = Invitation::where('code', '=', $model-&gt;invitation)-&gt;first()-&gt;role_id;
              $model-&gt;makeEmployee($role_id);
              $invitation_code = Invitation::where('code', '=', $model-&gt;invitation)-&gt;update(array('used_by' =&gt; $model-&gt;id));
          });
      }
  
      public function validate()
      {
          if (is_null(Invitation::where('code', '=', $this-&gt;invitation)-&gt;where('used_by', '=', '0')-&gt;first())) {
              throw new ValidationException(null, null, null, array('invitation' =&gt; "Грешен код."));
          } else {
              return true;
          }
      }
  
      public function updatePass($old_password, $new_password, $repeat_new_password)
      {
          $data = array(
              'old_password' =&gt; $old_password,
              'new_password' =&gt; $new_password,
              'repeat_new_password' =&gt; $repeat_new_password
          );
  
          $rules = array(
              'old_password' =&gt; 'required',
              'new_password' =&gt; 'required|min:8|max:30',
              'repeat_new_password' =&gt; 'required|same:new_password'
          );
  
          $validator = Validator::make($data, $rules);
  
          if ($validator-&gt;fails()) {
              throw new ValidationException(null, null, null, $validator);
          } else {
              $user = User::find(Auth::user()-&gt;id);
  
              if (Hash::check($old_password, $user-&gt;password)) {
                  $user-&gt;password = Hash::make($new_password);
  
                  if($user-&gt;save()) {
                      return true;
                  } else {
                      throw new ValidationException(null, null, null, array('mainError' =&gt; "Грешка с базата данни."));
                  }
              } else {
                  throw new ValidationException(null, null, null, array('old_password' =&gt; "Моля въведете правилно страта Ви парола."));
              }
          }
      }
  
      public function login($email, $password, $remember)
      {
          $data = array(
              'email' =&gt; $email,
              'password' =&gt; $password
          );
  
          $rules = array(
              'email' =&gt; 'required|email',
              'password' =&gt; 'required'
          );
  
          $validator = Validator::make($data, $rules);
  
          if ($validator-&gt;fails()) {
              throw new ValidationException(null, null, null, $validator);
          } else {
              if (User::where('email', '=', $email)-&gt;first()-&gt;block == true) {
                  throw new ValidationException(null, null, null, array('mainError' =&gt; "Акаунтът ви е блокиран."));
              } else {
                  $remember = ($remember) ? true : false;
                  if (Auth::attempt(['email' =&gt; $email, 'password' =&gt; $password], $remember)) {
                      return true;
                  } else {
                      throw new ValidationException(null, null, null, array('mainError' =&gt; 'Имейлът или паролата е грешна.'));
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>And Role Model:</p>
  
  <pre><code>&lt;?php
  
  class Role extends Eloquent {
  
      /**
       * The database table used by the model.
       *
       * @var string
       */
      protected $table = 'roles';
  
      protected $fillable = array('name');
      protected $guarded = array('id');
  
  
      /**
       * Set timestamps off
       */
      public $timestamps = false;
  
      /**
       * Get users with a certain role
       */
      public function users()
      {
          return $this-&gt;belongsToMany('User', 'users_roles');
      }
  }
  </code></pre>
  
  <p>I'm sorry for use of bulgarian language in exceptions</p>