theUnforgiven's avatar

Using messaging system

I'm using this package - https://github.com/cmgmyr/laravel-messenger But how can I use something to refresh after every minute or so so that messages get displayed.

0 likes
8 replies
theUnforgiven's avatar

Hi @cmgmyr great package by the way I didn't see the Laravel 5/pusher version til after I had watched the laracasts on pusher and just implemented how @JeffreyWay shows us and I've got it to work in a way just need a little tweaking now but all good thanks for providing the package.

tenantcloud's avatar

Hi @cmgmyr ! I'm using your package in my project and I have a problem with searching.

I need to search threads by participant firstName, lastName and email.

I'm trying to implement it in this way:

$threads = Thread::latest('updated_at')
                ->whereHas('participants', function($query) use($q) {
                    $query->whereHas('user', function($query) use($q) {
                        $query->where('lastName', 'LIKE', '%'.$q.'%');
                    })
                    ->orWhereHas('user', function($query) use($q) {
                        $query->where('firstName', 'LIKE', '%'.$q.'%');
                    })
                    ;

                })
                ->with(['participants' => function($query) {
                    $query->with('user');
                }])
                ->forUser($userId)
                ->paginate($limit)
            ;

It works fine if you search by lastName.But if you type firstName it will return the whole rows. To avoid this I've tried to comment :

->orWhereHas('user', function($query) use($q) {
        $query->where('firstName', 'LIKE', '%'.$q.'%');
})

And it works fine, but it is necessary no search by firstName or lastName or email.

Have you got any ideas? Or maybe more right and efficient way? Many thanks!

tenantcloud's avatar

I've changed query and it works fine now. If anyone need:

$threads = Thread::latest('updated_at')
                ->join('participants as part', 'part.thread_id', '=', 'threads.id')
                ->join('admins', function($join) use($q, $userId) {
                    //filter rows of my own
                    $join->on('admins.id', '=', 'part.user_id')
                        ->where('admins.id', '<>', $userId);
                })
                //search by firstName,lastName or email
                ->where('admins.lastName', 'LIKE', '%'.$q.'%')
                ->orWhere('admins.firstName', 'LIKE', '%'.$q.'%')
                ->orWhere('admins.email', 'LIKE', '%'.$q.'%')

                ->with(['participants' => function($query) {
                    $query->with('user');
                }])
                ->distinct()
                ->forUser($userId)
                ->paginate($limit)
            ;

Please or to participate in this conversation.