title: undefined method std class error in laravel
body: <p>This code related to our group project.when i use below code it is give    </p>
  
  <blockquote>
    <p>Call to undefined method stdClass::subjects().</p>
  </blockquote>
  
  <p>I tried many  ways but can not solved.</p>
  
  <p>following code part give the error</p>
  
  <pre><code> &lt;td&gt;{{$user-&gt;subjects()-&gt;get()[0]-&gt;name}},{$user-&gt;subjects()-&gt;get()[1]-&gt;name}}    &lt;/td&gt;
  @foreach($users as  $user)
  
      &lt;tr&gt;&lt;td&gt;{{$user-&gt;name }} &lt;/td&gt;
      &lt;td&gt;{{$user-&gt;email}} &lt;/td&gt;
      &lt;td&gt;{{$user-&gt;id}}    &lt;/td&gt;
  
    &lt;td&gt;{{$user-&gt;subjects()-&gt;get()[0]-&gt;name}},{$user-&gt;subjects()-&gt;get()[1]-&gt;name}}    &lt;/td&gt;
  &lt;/tr&gt;
  @endforeach
  </code></pre>
  
  <p>codes of Subject.php</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Subject extends Model
  {
        protected $table='subject';
  
      protected  $fillable = ['id','name','created_at','updated_at','user_id'];
  
      protected $primaryKey='id';
  
      public function user(){
        return $this-&gt;belongsTo('App\User');
  
  }
  </code></pre>
  
  <p>codes of User.php</p>
  
  <pre><code> &lt;?php
  
      namespace App;
  
      use Illuminate\Notifications\Notifiable;
      use Illuminate\Foundation\Auth\User as Authenticatable;
  
      class User extends Authenticatable
      {
          use Notifiable;
      protected $table='users';
  
          protected $fillable = [
              'usertype','name','lname', 'email','dob','school','phone','gender','password','verifyToken'
          ];
  
  
          protected $hidden = [
              'password', 'remember_token',
          ];
  
      )    
  
          }
  
           public function subjects()
          {
              return $this-&gt;hasMany('App\Subject','user_id','id');
          }
  
  
  
  
      }
  </code></pre>
  
  <p>codes of the controller shown as belows.I removed some codes parts to avoid this is very long.they are not caused to give errors</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Support\Facades\DB;
  use App\Http\Controllers\Controller;
  use Illuminate\Http\Request;
  use App\User;
  use App\Subject;
  use PDF;
  
  class pdfGenerator extends Controller
  {
  
  public function reportPdf()
  {
     $users = DB::table('users')-&gt;get();
     $pdf  = PDF::loadview('reports', ['users' =&gt; $users]); 
  
  
     return $pdf-&gt;download('report.pdf');
  }
  
    public function report()
      {
          $users = DB::table('users')-&gt;get();
  
          return view('reports', ['users' =&gt; $users]);
      }
  }
  </code></pre>