nahid / talk

Talk is a real-time users messaging and chatting system for Laravel.
MIT License
1.61k stars 327 forks source link

Talk::setAuthUserId in Constructor doesn't work in Laravel 5.4 #54

Closed rishabgarg closed 7 years ago

rishabgarg commented 7 years ago

I'm using Laravel 5.4 and realized that Talk::setAuthUserId(Auth::user()->id), doesn't work in constructor anymore. I have to call Talk::setAuthUserId in all the methods (chatHistory, ajaxSendMessage, ajaxDeleteMessage) explicitly.

Is there a fix for this in the latest version of Talk.

jampack commented 7 years ago

i have added this to my middleware for loggedin users.

nahid commented 7 years ago

From laravel 5.3 controller constructor execute before run middleware, so you can not access authenticated users info from controller constructor, check https://laracasts.com/discuss/channels/laravel/cant-call-authuser-on-controllers-constructor.

So the solution is, you can make a middleware and write this code in handlesection

if (Auth::check()) {
    Talk::setAuthUserId(Auth::user()->id)    
}
return $next($request);

and register this middleware in Kernel.php middleware array. I think this problem will solved.

Thank you