cjk
cjk

Hi, I've been struggling with this for a week with no success - any help will be most appreciated. I have a plugin, with a boot method, where I define a custom route. I need to get an id of a currently logged in front-end user (Rainlab Users plugin), but calling Auth::getUser() returns null.

public function boot() {
   Route::get('/test', function()
        { 
            $user = Auth::getUser();
            dd($user); //returns null
        });
}

I'll be grateful for any help, as I can't google any advice to this problem.

LukeTowers
LukeTowers

Routes should be defined in your plugin's routes.php file, and you need to make sure that the web middleware is included to ensure that the session is started and you have access to it.

Route::get('/test', function () {
    $user = Auth::getUser();
})->middleware('web');
cjk
cjk

Hi Luke,

That's exactly the bit of knowledge that I needed, thank you!

BTW, while I initially hesitated whether to go for OctoberCMS, after 2+ months of working with it on a daily basis, I find it to be just amazing, for so many reasons! Some of the design patterns that I questioned when I was starting, like the specific folder structure and splitting functionality into plugins, I now find to be a blessing.

mjauvin
mjauvin

Well said!

1-4 of 4