cmgmyr / laravel-messenger

Simple user messaging package for Laravel
MIT License
2.46k stars 517 forks source link

Not see the user name before the first reply #358

Closed omidMolaverdi closed 3 years ago

omidMolaverdi commented 3 years ago

Hi great folks.

Is there any easy way to hide the user name in the thread before the first reply?

cmgmyr commented 3 years ago

The blade files are just for example and sometimes to use as a starter. Feel free to add any logic you need to hide/show information.

omidMolaverdi commented 3 years ago

Thanks @cmgmyr. I have a bit of difficulty with the logic. do you have any recommendation please?

cmgmyr commented 3 years ago

You could probably change this line to something like this.

@if($thread->messages->count() > 1)
<h5 class="media-heading">{{ $message->user->name }}</h5>
@endif

But I'd probably create a new variable in the controller and pass it to the views so you only need to make that calculation once.

// Controller
$shouldShowUserNames = $thread->messages->count() > 1;

// View
@if($shouldShowUserNames)
<h5 class="media-heading">{{ $message->user->name }}</h5>
@endif