I have a simple function to accept a friend's request:
public function acceptFriend($id){
$user = User::find($id);
$sender = Auth::user();
$sender->acceptFriendRequest($user);
return redirect()->back();
}
It work's correctly but if other user send a friend's request, he send a notification. I want to mark as read it after accept request but I have a problem.I don't know how I can do query building to check this one notify. I know I can make a new function and like attirute use notify id but user of my website can accept request not only in notify list but in user's profile too.
I thought about read information form "data" column from "notifications" table but I have a problem. I try a few of query buildings:
$hello = auth()->user()->unreadNotifications->where('notifiable_id', Auth::user()->id)
->where('data->arr->id', '12')->first();
or
$hello = auth()->user()->unreadNotifications->where('notifiable_id', Auth::user()->id)
->where('data', '%12%')->first();
But it doesn;t works. "12" is id of sender,
The table structure is the normal notifications structure:
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
The data column will contain an array such as:
{
"title":"Something",
"arr":{
"id":12,
"name":"HelloWorld",
"avatar":null
}
}