This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

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.

JeffGoldblum
JeffGoldblum

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

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.