I want to save comments, posts and profiles that a user views in a viewable table. Posts and comments are displayed in a stream similar to social networks. How can I store the data in a viewable table in the background?
Table:
viewables
user_id
viewable_id
viewable_type
For example, if a user views or sees a post in the stream, the database should store the user_id and post_id. The same should be possible with comments and profiles.
EDIT:
The posts are issued in a forelse loop and the comments in a foreach.
@forelse ($posts as $post)
@if ($post->type === 1)
{{$post->body}}
@foreach ($post->comments as $comment)
{!!$comment->body!!}
@endforeach
@elseif ($post->type === 2)
{{$post->image}}
@foreach ($post->comments as $comment)
{!!$comment->body!!}
@endforeach
@elseif ($post->type === 3)
show post with type 3
@elseif ($post->type === 4)
show post with type 4
@else
show remaining
@endforelse