n Eloquent: Laravel 7+ Foreign Keys | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Eloquent: Laravel 7+ Foreign Keys

From Laravel 7, in migrations you don't need to write two lines for relationship field - one for the field and one for foreign key. Use method foreignId().

Before Laravel 7

Schema::table('posts', function (Blueprint $table)) {

From Laravel 7

Schema::table('posts', function (Blueprint $table)) {

Or, if your field is different from the table reference

Schema::table('posts', function (Blueprint $table)) {

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook