I have a web application TODO list. Users can add, modify, and delete tasks. Issue is that every user who log in to my web application can see all tasks that are created by other users. My idea is to add cell to tasks
database table with user_id
(ID of the user that created task), then somehow application get this user_id
and print out tasks with this ID. Can you describe please how can I realise this thing?
I am working with Laravel 10 and Vue.
I tried to get this users id and put in tasks database but it didn’t work out. I tried it to do with User and Task model.
2
Answers
You’ll need to associate each task with the user who created it and then filter tasks based on the logged-in user’s ID.
references the id of the user in your users table.
model can have many Tasks.
there can be multiple ways to handle this.
you need to create a relationship between users and tasks.
create a foreign key in tasks table (user_id) and save when you are saving the task.
In controller function, all you need to call the values like this