mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 13:24:03 +00:00
18 lines
No EOL
501 B
Markdown
18 lines
No EOL
501 B
Markdown
---
|
|
title: 'Laravel migrations have a very nice syntax for foreign keys'
|
|
tweet_id: '1308126491188883463'
|
|
thread_slug: 1-rt-1-tip
|
|
author_username: samuelstancl
|
|
images: { }
|
|
created_at: 2021-04-06T16:07:46+00:00
|
|
slug: laravel-migrations-have-a-very-nice-syntax-for-foreign-keys
|
|
---
|
|
|
|
I didn't know about this for so long.
|
|
|
|
Instead of:
|
|
$table->unsignedBigInteger('user_id');
|
|
$table->foreign('user_id')->references('id')->on('users');
|
|
|
|
You do:
|
|
$table->foreignId('user_id')->constrained(); |