Closed 13dev closed 7 years ago
In inbox message are already count unread messages.
@nahid which method should we use for count unread messages?
getInbox
@13dev Below is how I write the codes,
Controller
$threads = Talk::threads(); return view('inbox', ['threads' => $threads]);
View
@foreach($threads as $value) {{dd($value)}} @endforeach
I use threads cuz threads are alias to getInbox, but even if i dump it, i still couldn't see the unread messages, what is the object name ?
you have this?
Talk::setAuthUserId(auth()->user()->id);
Yes, i put it as a constructor public function __construct() { Talk::setAuthUserId(Auth::user()->id); }
in controller dd($threads); before return and watch if returning anything
and dd(Auth::user()->id);
uh, yes, it does return something, same goes to the view that i commented just now, i just didn't know which object name it would be.
{#383 ▼ +"thread": Message {#388 ▼
+timestamps: true
#touches: array:1 [▶]
+fillable: array:6 [▶]
#connection: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
#attributes: array:9 [▶]
#original: array:9 [▶]
#relations: array:1 [▶]
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#dateFormat: null
#casts: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
} +"withUser": User {#381 ▶} }
watch fillable
+fillable: array:6 [▼
0 => "message"
1 => "is_seen"
2 => "deleted_from_sender"
3 => "deleted_from_receiver"
4 => "user_id"
5 => "conversation_id"
]
is_seen return if message is read or not
alright, so i have to loop and count manually ? since im trying to get the total unread message.
you have to use getconversationByUserId()
done
how i can count all unread messages of user ?