title: Trying to get property 'id' of non-object Laravel 7.X
body: <p>Now I have two Models: user.php and Trx.php. I have created a one to many relationships as below:</p>
  
  <p>User Model:</p>
  
  <pre><code>public function transactions()
      {
          return $this-&gt;hasMany('App\Trx');
      }
  </code></pre>
  
  <p>Trx Model:</p>
  
  <pre><code> public function user()
      {
          return $this-&gt;belongsTo('App\User');
      }
  </code></pre>
  
  <p>And this is the controller method for process data from Trx.php model and sending data to the views:</p>
  
  <pre><code>public function purchasedPlan()
      {
          $page_title = 'Purchased Plan';
          $transactions = Trx::where('type', 7)-&gt;orderBy('id', 'DESC')-&gt;paginate(config('constants.table.default'));
          $empty_message = 'No data found.';
          // dd($transactions);
          return view('admin.reports.transactions', compact('page_title', 'transactions', 'empty_message'));
  
      }
  </code></pre>
  
  <p>Now the problem is that when I try accessing the data from the model, that's the $transactions, everything is working well except when I try getting the user in the relationship established like this in the blade template:</p>
  
  <p>transactions.blade.php</p>
  
  <pre><code>&lt;td&gt;  &lt;a href="{{ route('admin.users.detail', $trx-&gt;user-&gt;id) }}"&gt;{{ $trx-&gt;user-&gt;username }}&lt;/a&gt;&lt;/td&gt;
  </code></pre>
  
  <p>With that, I get this error:</p>
  
  <pre><code>Error:
  [2020-05-24 05:35:40] production.ERROR: Trying to get property 'id' of non-object (View: /home/icashers/public_html/acc/core/resources/views/admin/reports/transactions.blade.php) {"exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object (View: /home/icashers/public_html/acc/core/resources/views/admin/reports/transactions.blade.php) 
  </code></pre>
  
  <p>What am I doing wrong please? Anyone who's seeing what I am not please help. Thank you in advance</p>
  
  <p>Trx.php Migration</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateTrxesTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('trxes', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;integer('user_id')-&gt;nullable();
              $table-&gt;string('amount',50)-&gt;nullable();
              $table-&gt;string('main_amo',50)-&gt;nullable();
              $table-&gt;string('charge',50)-&gt;nullable();
              $table-&gt;string('type',50)-&gt;nullable();
              $table-&gt;string('title')-&gt;nullable();
              $table-&gt;string('trx')-&gt;nullable();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('trxes');
      }
  }
  </code></pre>
  
  <p>User.php Migration:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateUsersTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('users', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('firstname');
              $table-&gt;string('lastname');
              $table-&gt;string('username')-&gt;unique();
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('mobile')-&gt;unique();
              $table-&gt;decimal('balance', 11, 2)-&gt;default(0);
              $table-&gt;string('password');
              $table-&gt;string('image')-&gt;nullable();
              $table-&gt;text('address')-&gt;nullable()-&gt;comment('contains full address');
              $table-&gt;tinyInteger('status')-&gt;default(1)-&gt;comment('0: banned, 1: active');
              $table-&gt;tinyInteger('ev')-&gt;default(0)-&gt;comment('0: email unverified, 1: email verified');
              $table-&gt;tinyInteger('sv')-&gt;default(0)-&gt;comment('0: sms unverified, 1: sms verified');
              $table-&gt;string('ver_code')-&gt;nullable()-&gt;comment('stores verification code');
              $table-&gt;dateTime('ver_code_send_at')-&gt;nullable()-&gt;comment('verification send time');
              $table-&gt;tinyInteger('ts')-&gt;default(0)-&gt;comment('0: 2fa off, 1: 2fa on');
              $table-&gt;tinyInteger('tv')-&gt;default(1)-&gt;comment('0: 2fa unverified, 1: 2fa verified');
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('users');
      }
  }
  </code></pre>