title: Laravel object_get
body: <p>I have a base <code>User</code> model object. Each user can be either a staff member, parent or student. Each account type also has an associated model.</p>
  
  <p>For example:</p>
  
  <pre><code>class User extends Model {
  
      public function details()
      {
          switch($this-&gt;account_type) {
              case 'staff':    return $this-&gt;hasOne(Staff::class);
              case 'student':  return $this-&gt;hasOne(Student::class);
              case 'parent':   return $this-&gt;hasOne(ParentUser::class);
          }
  
          return null;
      }
  </code></pre>
  
  <p>If I run:</p>
  
  <pre><code> echo $user-&gt;details-&gt;staff_code;
  </code></pre>
  
  <p>Then it outputs <code>CRS</code> for example. However, if I run it with <code>object_get()</code>:</p>
  
  <pre><code>object_get($user, 'details.staff_code');
  </code></pre>
  
  <p>Then it outputs <code>null</code>.</p>
  
  <p>I figured because in the <code>object_get()</code> method, it has this line:</p>
  
  <pre><code>if (! is_object($object) || ! isset($object-&gt;{$segment}))
  </code></pre>
  
  <p>I assume because the <code>details</code> property is a magic/dynamic laravel model property, <code>isset()</code> doesn't work on it. </p>
  
  <p>Whats the best way to handle this? Is it safe to edit the <code>object_get()</code> method and replace the <code>isset()</code> segment with something more robust? I don't really want to edit source code in the Vendor directory.</p>
  
  <p>Should I create my own <code>object_get</code> helper function, and if so, where should I place it / autoload it?</p>
  
  <p>Is there another method of achieving the result I want that I'm unaware of?</p>
  
  <p>Any help is appreciated.</p>