SleepingOwlAdmin / demo

This is demo application for SleepingOwl Admin.
http://demo.sleepingowladmin.ru
93 stars 55 forks source link

Can't get auth infomation in Admin section #8

Closed xcaptain closed 8 years ago

xcaptain commented 8 years ago

http://demo.sleepingowladmin.ru/admin/contacts2

This page can be accessed without login, if that's a bug I can help work on it.

xcaptain commented 8 years ago

I think it's a bug, https://github.com/LaravelRUS/SleepingOwlAdmin/blob/development/src/Providers/AdminServiceProvider.php#L65 this line executed before route, so middleware config doesn't work.

Is there any way to get the current user in admin page?

butschster commented 8 years ago

Hi. No. Just i deleted auth middleware from config https://github.com/LaravelRUS/SleepingOwlAdmin/commit/29194c4aa07bc9c0a581a0544d3863a8da05f459#diff-ff9838bfdccf5addada05fe70eabfbcfL46

xcaptain commented 8 years ago

@butschster I added auth middleware to my config, it worked fine and will force redirect to login. but I still can't get current user in app/Admin/Contact.php. \Auth::user() returns null.

butschster commented 8 years ago

Show me code.

You should add auth middleware, like this

'middleware' => ['web', 'auth'],

and

AdminSection::registerModel(Post::class, function (ModelConfiguration $model) {
    // Display
    $model->onDisplay(function () {
         dd(auth()->user());
    });
})->addMenuPage(Post::class);
xcaptain commented 8 years ago

Thanks, I found my mistake, I was doing

AdminSection::registerModel(Post::class, function (ModelConfiguration $model) {
    // Display
    dd(auth()->user());
    $model->onDisplay(function () {

    });
})->addMenuPage(Post::class);]

so I got null