title: Laravel Call to a member function first() on null
body: <p>I'm using VueJS and Laravel for an application I'm developing. I've tried to search here for an answer, but I haven't found anything that works. Most of the times, it's because there's really nothing to return, but I've tried to debug my query quite a bit, and I don't understand why I keep getting a null.</p>
  <p>So I'm trying to get information about the student who's logged in, so I'm doing an axios get on a route that executes the following:</p>
  <pre><code>public function getByUserId($id) {
      //$student = $this-&gt;studentRepo-&gt;findByUserId($id);
      $student = Student::where('user_id', $id)-&gt;first();
      $inscription = Inscription::where('student_id', $student-&gt;id)-&gt;first();
      $student-&gt;careers;
  
      $res = $inscription ? new InscriptionResource($inscription) : '';
  
      return response()-&gt;json([
          'student' =&gt; new StudentResource($student),
          'inscription' =&gt; $res,
      ]);
  }
  </code></pre>
  <p>The thing is, it doesn't find the student with that user_id. I've checked if the user_id (param: $id) is getting there as expected and it is. I've also tried to get the query via -&gt;toSql() and copy pasted the query on the database to test it and I do get the student I'm trying to search for. Thing is, it's not finding it in Laravel for some reason, I'm not sure why.</p>
  <p>My student table does have the attribute &quot;user_id&quot;, I've checked.</p>
  <p>Student file:</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\SoftDeletes;
  
  class Student extends Model {
      use SoftDeletes;
      protected $dates = ['deleted_at'];
  
      public function charges() {
          return $this-&gt;hasMany('App\Models\Payment');
      }
  }
  </code></pre>