Tags down


How to add auth user id or session to logging in Laravel 5.7?

By : djhspence
Date : October 17 2020, 08:10 AM
With these it helps Based on the answer of DigitalDrifter and part of this post from Emir Karşıyakalı I managed to get a fair enough solution.
I could not grab the User ID since (as per my understanding at this point) it can't be resolved just yet. But I felt satisfied with getting a more or less accurate client id and session id, so I can trace a user interaction thread on logs:
code :

namespace App\Loggers;

use Monolog\Formatter\LineFormatter;

class LocalLogger
    private $request;

    public function __construct(\Illuminate\Http\Request $request)
        $this->request = $request;

    public function __invoke($logger)
        foreach ($logger->getHandlers() as $handler) {

    protected function getLogFormatter()
        $uniqueClientId = $this->getUniqueClientId();

        $format = str_replace(
            '[%datetime%] ',
            sprintf('[%%datetime%%] %s ', $uniqueClientId),

        return new LineFormatter($format, null, true, true);

    protected function getUniqueClientId()
        $clientId = md5($this->request->server('HTTP_USER_AGENT').'/'.$this->request->ip());
        $sessionId = \Session::getId();

        return "[{$clientId}:{$sessionId}]";
    // config/logger.php

    'syslog' => [
        'driver' => 'syslog',
        'level'  => 'debug',
        'tap'    => [App\Loggers\LocalLogger::class],
Dec 11 13:54:13 trinsic Fimedi[13390]: [2018-12-11 16:54:13] c6c6cb03fafd4b31493478e76b490650 local.INFO: Hello world
Dec 11 13:55:44 trinsic Fimedi[13390]: [2018-12-11 16:55:44] [c6c6cb03fafd4b31493478e76b490650:xUs2WxIb3TvKcpCpFNPFyvBChE88Nk0YbwZI3KrY] local.INFO: Hello world

Share : facebook icon twitter icon

Laravel 4: how to remember a user when logging him in using Auth::login

By : Aldo Vela
Date : March 29 2020, 07:55 AM
will be helpful for those in need My users can login using social options (Facebook, Twitter) and so I don't use the Auth::attempt() method, but the Auth::login(). , It is not in the docs, but if you look at the code;
code :
public function login(UserInterface $user, $remember = false)
Auth::login($user, true);

Where to add Auth session variables when the user is logging in

By : Utsav
Date : March 29 2020, 07:55 AM
will be helpful for those in need Auth::user() will have the logged in user object from which you should be able to access all its properties.
edit: if the currency is a property of a related model then you should have your relations set up, maybe something like this in the User model:
code :
public function group()

Laravel Auth::user() session custom?

By : เป้าหมาย มีไว้พุ่งชน
Date : March 29 2020, 07:55 AM
it should still fix some issue I have three table in database. one is users and second one is role and other is user_role. , Create relationship in User model
code :
public function roles()
    return $this->belongsToMany(Role::class);
public function users()
    return $this->belongsToMany(User::class);
public function hasRole($role)
    return $this->roles->contains('id', $role);

Laravel auth cannot logout and User session always filled

By : Donia M Fekry
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Laravel 5.4+ uses post method for logout so instead of simple url (get) request you should post a form to logout.
Try Something Like this
code :
<a href="#" onclick="document.getElementById('logout-form').submit();"> Logout</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    {{ csrf_field() }}

Laravel Auth Logout() + Session Flush() not logging out user

By : Connor Adams
Date : March 29 2020, 07:55 AM
I wish this helpful for you I've been experiencing inability to successfully logout of my application for about 3 months. , try using
Privacy Policy - Terms - Contact Us © voile276.org