M
M
maiskiykot2020-07-01 21:48:10
Laravel
maiskiykot, 2020-07-01 21:48:10

How to get the admin session data in the controller?

It was necessary to make an if(Auth::user()->isAdmin()) condition in the Http controller and it turned out that user = null. There is a session token, @role is displayed in templates. I can not understand: what is needed in order to get session data? I can't even get my login.

public function __construct()
    {
     if (config(....)) - это то, что сейчас работает и я хочу заменить на Auth:user()->role('Admin')
     $this->middleware('auth.basic');
  
   }

I understand that in Laravel, authentication is focused on the frontend, but on the backend you need to cut it yourself? If you point to an implementation example for general development, I will be grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
f0kusn1k, 2020-07-02
@f0kusn1k

Hi, to get session data use:

$data = session()->get('ключ'); 
dd($data);

You do it in the controller :) Describe the situation in more detail, what you would like and what does not work. Little info :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question