title: Null when var dumping for querying eloquent database?
body: <p>I'm trying to var_dump a table of users associated with a task, and im getting </p>
  
  <p>NULL</p>
  
  <p>Ultimately im trying to get a Task and associated it with the user, im not sure if im doing it correct.</p>
  
  <p>This is using <a href="https://laravel.com/docs/5.1/eloquent" rel="nofollow noreferrer">eloquent</a> in Slim. </p>
  
  <pre><code>&lt;?php
  
  
  namespace App\Controllers;
  
  use Slim\Http\Request;
  use Slim\Http\Response;
  use Illuminate\Database\Capsule\Manager as DB;
  use App\Models\Task;
  
  use App\Models\User;
  
  class TodosController extends BaseController
  {
  
      public function getTodos($request, $response, $args)
      {
          // $sth = $this-&gt;db-&gt;prepare("SELECT * FROM tasks ORDER BY task");
          // $sth-&gt;execute();
          // $use = User::all();
          // below
          // $todos = DB::table('tasks')
     //             -&gt;join('users', 'users.id', '=', 'tasks.user_id')
     //             -&gt;get();
  
          $todos = User::find(1)-&gt;tasks()-&gt;first();
  
          var_dump($todos);
  
          return $this-&gt;c-&gt;view-&gt;render($response, 'todos.twig', ['todos' =&gt; $todos]);
  
      }
  </code></pre>
  
  <p>Todos.twig</p>
  
  <pre><code>{% extends "templates/layout.html" %}
  
  {% block content %}
  &lt;h1&gt;My Todos&lt;/h1&gt;
  
  &lt;ol&gt;
    {% for task in todos %}
          &lt;div id="task{{task.id}}" class="myl" ng-controller="myCtrl"&gt;
          &lt;li&gt;&lt;h4&gt;{{ task.task}}&lt;/h4&gt;&lt;/li&gt;
          &lt;small style="font-style:italic"&gt;{{task.created_at |date("m/d/Y")}}&lt;/small&gt;&lt;/br&gt;
          &lt;small style="font-style:italic"&gt;{{task.user.id}}&lt;/small&gt;&lt;/br&gt;
  
  
  
  
      &lt;button id="disappear" name="task" class="btn btn-sm btn-danger" ng-click="deleteTask({{task.id}})"&gt;Delete&lt;/button&gt;
  
  
  
          &lt;/div&gt;
      {% endfor %}
  
  &lt;/ol&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>Updated</strong> </p>
  
  <p>This is what my other files of code look like. </p>
  
  <p>Not sure on why im getting the error </p>
  
  <p>User Model</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  
  use Illuminate\Database\Eloquent\Model;
  
  
  class User extends Model 
  {
      protected $table = 'users';
      protected $fillable = ['username', 'password'];
      public $timestamps = [];
  
  
      public function tasks()
      {
          return $this-&gt;hasMany('App\Models\Task', 'user_id');
      }
  }
  </code></pre>
  
  <p>Task Model </p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  
  // use Slim\Views\Twig as View;
  // use Interop\Container\ContainerInterface;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Task extends Model
  {
  
      protected $table = 'tasks';
      protected $fillable = ['task', 'user_id'];
  
      public $timestamps = [];
  
  
      public function user()
      {
          return $this-&gt;belongsTo('App\Models\User', 'user_id');
      }
  
  }
  </code></pre>
  
  <p>Updated</p>
  
  <p><a href="https://i.stack.imgur.com/89kYK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/89kYK.png" alt="enter image description here"></a></p>