I'm currently working on Laravel blog App. I want to display posts is bookmarked by loggedin user or not on blade template view .
On Click of post's bookmark button , Im calling ajax function and that is working correctly.
but when i request to page /posts
it shows all posts with same color bookmarks
but not showing bookmarked posts bookmark button with red color
i want to distinguish post on page render if it is bookmared by logged in user or not .
I have 3 tables in mysql database : users
, posts
, bookmarks
table
structure users table : (id,name,email,password,...)
structure posts table : (id,title,body,user_id, ...)
structure bookmarks table : (user_id,post_id,created_at,updated_at)
here is code for showing bookmark icon in blade view
<span class="desktop-post-read-later">
@if(Auth::guest())
<span class="post-read-later" data-type="add" data-id="{{$post->id}}" title="Please login to bookmark this post!">
<i class="bookmark fa fa-bookmark-o" id="bookmark_{{$post->id}}"></i>
</span>
@else
<span class="post-read-later" data-type="add" data-id="{{$post->id}}">
@if( ????? what condition here i have to put ??????)
<i class="bookmark fa fa-bookmark-o" id="bookmark_{{$post->id}}" style="color:red"></i>
@else
<i class="bookmark fa fa-bookmark-o" id="bookmark_{{$post->id}}"></i>
@endif
</span>
@endif