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 7Schema::table('posts', function (Blueprint $table)) { $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users');} // From Laravel 7Schema::table('posts', function (Blueprint $table)) { $table->foreignId('user_id')->constrained();} // Or, if your field is different from the table referenceSchema::table('posts', function (Blueprint $table)) { $table->foreignId('created_by_id')->constrained('users', 'column');}
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses on Laravel Daily
AI Agents/IDEs for Laravel: May 2026 (Claude Code, Codex, OpenCode, etc)
7 lessons
52 min
Roles and Permissions in Laravel 13
14 lessons
57 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read