Cover image for Laravel 7 short-cuts to writing foreign keys

Laravel 7 short-cuts to writing foreign keys

wolfiton profile image wolfiton ・1 min read

Hi everyone,

Today I want to write about a quick tip to use when writing foreign keys in Laravel 7.

This method will help you write shorter migrations and make your code more readable.

For our example, I am going to use the user_id which is very common but this can be applied to any foreign key.

In the past we would write something like this:



Hmm, pretty verbose right?

The good news Dear reader is that we can write now like this:


Much nicer and easier to read, I hope you enjoyed this tip Dear Reader.

If you find it useful share it on social with your friends.

Have a nice day.


Image cover: Long Road

Posted on by:

wolfiton profile



I am a certified trainer that likes to share my knowledge with the world. Also, I am an adopter of continuous learning and evolving idea. https://dev.to/wolfiton/who-am-i-3lj7


Editor guide