Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

splaq's avatar

Has anyone used the Cmgmyr/laravel-messenger?

Has anyone used this? I'm having some issues getting it to work, my user table is setup a little different, I have fname and lname for the name fields and the laravel-messenger .... extension?.. keeps telling me...

ErrorException in Connection.php line 651:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.name' in 'field list' (SQL: select concat(users.name) as email from `users` inner join `participants` on `users`.`id` = `participants`.`user_id` where `participants`.`thread_id` = 2 and `users`.`id` != 10) (View: /home/gbartels/registration/resources/views/messenger/index.blade.php)

I've checked messenger/index.blade.php and replaced all occurrences of ->name with ->email (did that with other files in the package as well)

So, I'm not really sure what's going on, any suggestions? Here's a link to his github repo..

https://github.com/cmgmyr/laravel-messenger

Also, does this forum have a search feature? It should :P

0 likes
6 replies
BrianVeltman's avatar
Level 12

Yes I'm using it without any major issues.

In your case you have to modify the Threads model.

The colums are more or less hardcoded within the createSelectString and ParticipantsString methods.

public function participantsString($userId = null, $columns = ['name'])
    {
        $participantTable = $this->getParticipantTable();
        $usersTable = $this->getUsersTable();
        $selectString = $this->createSelectString($columns);
        $participantNames = $this->getConnection()->table($usersTable)
            ->join($participantTable, $usersTable . '.id', '=', $participantTable . '.user_id')
            ->where($participantTable . '.thread_id', $this->id)
            ->select($this->getConnection()->raw($selectString));
        if ($userId !== null) {
            $participantNames->where($usersTable . '.id', '!=', $userId);
        }
        $userNames = $participantNames->lists($usersTable . '.name');
        return implode(', ', $userNames);
    }

---

protected function createSelectString($columns)
    {
        $dbDriver = $this->getConnection()->getDriverName();
        $tablePrefix = $this->getConnection()->getTablePrefix();
        $usersTable = $this->getUsersTable();
        switch ($dbDriver) {
        case 'pgsql':
        case 'sqlite':
            $columnString = implode(" || ' ' || " . $tablePrefix . $usersTable . '.', $columns);
            $selectString = '(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
            break;
        case 'sqlsrv':
            $columnString = implode(" + ' ' + " . $tablePrefix . $usersTable . '.', $columns);
            $selectString = '(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
            break;
        default:
            $columnString = implode(", ' ', " . $tablePrefix . $usersTable . '.', $columns);
            $selectString = 'concat(' . $tablePrefix . $usersTable . '.' . $columnString . ') as name';
        }
        return $selectString;
    }
BrianVeltman's avatar

And yea, at the top left of 'Library' there's a search button.

splaq's avatar

Ahhh... Got it.. so another question as I'm still kind of new to laravel.. but was I correct to copy the models from the vendor directory to my app directory? Or should those have been published when I did the vendor:publish command?

splaq's avatar

Ok so I changed all occurrences of "name" or ".name" to "email" or ".email" NOW.. it's telling me that in index.blade.php I'm trying to get a property of a non object..

Here's my index.blade.php (it's the default from the package... ) I figured i'd get it working with all the defaults see how it all works then start making the changes I need.. but anyways..

@extends('layouts.master')

@section('content')
    @if (Session::has('error_message'))
        <div class="alert alert-danger" role="alert">
            {!! Session::get('error_message') !!}
        </div>
    @endif
    @if($threads->count() > 0)
        @foreach($threads as $thread)
        <?php $class = $thread->isUnread($currentUserId) ? 'alert-info' : ''; ?>
        <div class="media alert {!!$class!!}">
            <h4 class="media-heading">{!! link_to('messages/' . $thread->id, $thread->subject) !!}</h4>
            <p>{!! $thread->latestMessage->body !!}</p>
            <p><small><strong>Creator:</strong> {!! $thread->creator()->email !!}</small></p>
            <p><small><strong>Participants:</strong> {!! $thread->participantsString(Auth::id()) !!}</small></p>
        </div>
        @endforeach
    @else
        <p>Sorry, no threads.</p>
    @endif
@stop 

The only thing I changed was

{!! $thread->creator()->name !!} to {!! $thread->creator()->email !!}
laracraft's avatar

Glad to find this as I am having similar issues. I need to change .name to .first_name in the Threads model but am not exactly sure where that file should reside.

@BrianVeltman, You mention "you have to modify the Threads model." Is this in the \vendor\cmgmyr\messenger\src\Cmgmyr\Messenger folder or have you moved those into the app folder?

Just wondering what would happen when updating the package in the future.

Thanks in advance!

BrianVeltman's avatar

@laracraft If you update it will break. But I've seen an issue on Github to get this fixed. I just changed it to play around with it.

1 like

Please or to participate in this conversation.