Widget class role authentication

  • I have created and showed some widget in dashboard. Can I filter in my Widget class (implemented from BaseWidget) in order to show specific widgets with different roles (I have Admin and Sub Admin roles) ? The main thing is I cannot use any methods to get logged in user info. I tried:

    1. use Modules\User\Contracts\Authentication, then app(Authentication::class)->user() => get null
    2. \Auth::check() or \Auth::user => get null

    I am happy when anyone help :)

  • use Modules\User\Contracts\Authentication;
    class DashboardController extends AdminBaseController
    * @var Authentication
    private $auth;

    public function __construct( Authentication $auth)
        $this->auth = $auth;

    public function index()
    $logged_in_user= $this->auth->user();
    return $logged_in_user;

  • Thank you for your reply :)
    I have seen it in Dashboard controller. But I avoid to edit the code in Dashboard controller. It may override when user runs composer update command :( so that's why I find the way to use Auth in our Widget class.

Log in to reply

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.