Laravel: how to add a foreign key reference for user

If you need to add a foreign key reference to the user in the foreign table, you should know that id column formats must match  in users & new tables.


Create a user table (by default in Laravel 8):

Schema::create('users', function (Blueprint $table) {

In this case, we see that the type of id is not clearly specified, but if you look in the database, you can see that it is bigint(20)


Add foreign key reference example:

Schema::create('example_table', function (Blueprint $table) {





No comments yet, you can leave yours: