Associating Entities and Handler Functions with the User
Learn to fetch the user from the session and to associate entities with the user.
Till now, all notes were visible to all users. We will add a foreign key user_id
to the notes
table. The column user_id
stores the Id
of the user to whom the note belongs.
Then, we will change the handler functions to get the user identifier from the session to carry out the dtabase operations in the user’s context.
Associating notes with users
To associate notes with users, we need to do the following:
Create a new migration that adds the foreign key
user_id
to thenotes
table.Alter the
Note
model to add user ID to the model structure and methods.
Creating a migration
We begin by creating a new migration to add user_id
to the notes
table.
Get hands-on with 1400+ tech skills courses.