1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 05:14:04 +00:00
laravel-tips/content/tips/laravel-migrations-have-a-very-nice-syntax-for-foreign-keys.md
2021-04-07 20:16:47 +02:00

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: 2020-09-21T19:30:33+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();