title: Laravel: Multiple tables in one model
body: <p>I have the following model for Users:</p>
  
  <pre><code>class User extends Authenticatable
  {
      use Notifiable;
      protected $table = 'login_info';
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'name', 'email', 'password',
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      public function getDashboards()
      {
          return \DB::table('dashboard')
                 -&gt;select('type')
                 -&gt;where('id', Auth::id())
                 -&gt;orderBy('column', 'asc')
                 -&gt;get();
      }
  }
  </code></pre>
  
  <p>Users have different information in many tables </p>
  
  <ul>
  <li>user info like name, office, dashboard,2FA etc</li>
  </ul>
  
  <p>Is the way I do it now <strong>"best practice"</strong> (like the <code>getDashboards</code> function) for getting information from different tables?</p>
  
  <p>Or should I create a model for each of the tables and then <strong>"join them"</strong> (<code>hasMany</code>, <code>belongsToMany</code>, and so on) for each of the tables?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I am now using models, but the result of the query is always an empty array.</p>
  
  <pre><code>class Dashboard extends Model
  {
      protected $table = 'dashboard';
  
      public function user()
      {
          return $this-&gt;belongsTo(User::class,'user_id','id');
          //user_id
      }
  }
  </code></pre>
  
  <p><code>user_id</code> is the id of the user which is used in the login_info table.</p>
  
  <p>And in the User class I have:</p>
  
  <pre><code>public function dashboards()
  {
      return $this-&gt;hasMany(Dashboard::class,'id','user_id');
  }
  </code></pre>
  
  <p>In the login controller I have:</p>
  
  <pre><code>$user = \App\User::find(1);
  $user-&gt;dashboards;
  </code></pre>
  
  <p>Anyone see what the problem could be?</p>
  
  <p>Thanks for any help!</p>