How to display the user record from the database in Laravel?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
12 views
We need to display the user posts on his page.

In User.php added relation

public function post(){
return $this->hasMany('App\\post');
}

The output on the page using @foreach($posts as $post)
{{ $post->content }}

Now displays all posts from all users.
by | 12 views

1 Answer

0 like 0 dislike
If in the following diagram something doesn't work look for a problem in your code:
// User Model public function posts () { return $this->hasMany(Post::class); } // Controller (if needed) public function index () { $posts = Auth::user()->posts; } // View @foreach($posts as $post) {{ $post->content }} @endforeach
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
5 answers
asked Apr 10, 2019 by alt22
110,608 questions
257,187 answers
0 comments
40,796 users