title: How to add user to another table after user registration in laravel?
body: <p>I am developing an e-commerce project in <strong>Laravel 5.6</strong> in which I have two tables for users :</p>
  
  <ol>
  <li><strong>Users</strong> for passwords and some other stuff and</li>
  <li><strong>UserDetails</strong> table for storing user address, phone, city, pin code, etc.</li>
  </ol>
  
  <p>While registering a user with storing credentials in the <strong>Users</strong> table I want to make a column in the <strong>UserDetails</strong> table with the same user_id that has been generated while adding to <strong>Users</strong> table.</p>
  
  <p>Below is my migrations :</p>
  
  <pre><code>Schema::create('users', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password');
              $table-&gt;timestamp('email_verified_at')-&gt;nullable();
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
  
  
  Schema::create('user_details', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('phone')-&gt;nullable();
              $table-&gt;string('city')-&gt;nullable();
              $table-&gt;string('pincode')-&gt;nullable();
              $table-&gt;unsignedInteger('user_id');
              $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>I had tried to add following in the <strong>create</strong> function in <strong>RegisterController</strong></p>
  
  <pre><code>protected function create(array $data)
      {   
          User::create([
              'name' =&gt; $data['name'],
              'email' =&gt; $data['email'],
              'password' =&gt; Hash::make($data['password']),
          ]);
  
          UserDetails::create([
              'user_id' =&gt; Auth::user()-&gt;id
          ]);
  
          return;
      }
  </code></pre>
  
  <p>But it doesn't work and shows </p>
  
  <p><code>Trying to get property 'id' of non-object"</code>.</p>
  
  <p>Help me through this.</p>