I
I
iAlex1952018-04-30 17:28:24
Laravel
iAlex195, 2018-04-30 17:28:24

How to get data from DB in Laravel?

Good day.
The user has a page where he can write posts. How can I display the posts of a specific user from the database on his page? At me posts of all users are stored in one table. Where there is 1. post id, 2. user id, 3. post itself. I'm trying to display his posts from the database on the user's page, but all the posts of all users are displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-04-30
@iAlex195

Laravel relationships
For users, you need to add a relation pointing to the post model, and then the user's posts will be accessible through a simple view construction:
$user->posts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question