1. Home
  2. Laravel
  3. Foreign key

Set a foreign key in the data base table. Makes a reference between tables using an id and a foreign key.

// Migration example
public function up(){
    Schema::create('subitems', function (Blueprint $table) {
        // Create all table fields
        // Set the foreign key
        // Append the function below if you want to automatically remove all Subitems related to the Item
        // onDelete('cascade')
Full Laravel cheatsheet