title: Laravel - How to find foreign key value
body: <p>first time working with Laravel and PHP. I am trying to insert row in the table <strong>profile</strong> where the attribute uID is a foreign key referencing to uID on <strong>user</strong> table, but getting errors. How do I insert just the summary attribute of the profile and set the uID (foreign key) automatically. I can insert users with uID without any problems. Here are my model and controller files. Thanks!</p>
  
  <p>user model
      
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
      class user extends Model
      {
      // specify which attributes can be filled out during registration
      public $timestamps = false;
      protected $fillable=['firstname','lastname','email','password',];
  
      public function profile(){
        return $this-&gt;hasOne(profile::class);
      }
  }
  </code></pre>
  
  <p>profile model
      
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class profile extends Model
  {
      //
      public $timestamps = false;
      protected $fillable = ['summary',];
  
      public function user(){
        return $this-&gt;belongsTo(user::class);
      }
  }
  </code></pre>
  
  <p>profile migration
      
  
  <pre><code>use Illuminate\Support\Facades\Schema;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateProfilesTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
       // create profile table
         Schema::create('profiles', function (Blueprint $table) {
             $table-&gt;increments('pID');
             $table-&gt;timestamp('created_at')-&gt;useCurrent();
             $table-&gt;string('summary')-&gt;default('');
             $table-&gt;unsignedInteger('uID');
  
             $table-&gt;foreign('uID')-&gt;references('uID')-&gt;on('users')-&gt;onDelete('cascade');
         });
     }
  }
  </code></pre>
  
  <p>profile controller
      
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\profile;
  
  class ProfileController extends Controller
  {
      public function create()
      {
          //
          return view('profile.create');
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
          // used to store user profile after validation
          $this-&gt;validate($request,[
            'summary' =&gt; 'required'
          ]);
          $profile = new profile([
            'summary' =&gt; $request-&gt;get('summary'),
            'uID' =&gt; $request-&gt;user()-&gt;uID
          ]);
  
          return redirect()-&gt;route('profile.create')-&gt;with('success','Profile created');
      }
  }
  </code></pre>