I need help and advice on the following topic.
My boos has a simple Apache server setup and a simple php auth setup . Once the user is verified with a panel like this.

He / she has access to all the applications that are behind him. Thus, in other words, this panel serves as a βgateβ, if you are outside the gate, then you have access (of course, there is a permissions table on the web server).
Problem
The application that I create using Laravel 5 needs to be run behind the gate, so this means that the application must know who the user is.
Using $_SERVER['PHP_AUTH_USER']; , I can get the username that is currently registered.
But what if I want to track user's actions in my application? I need something like $this->user_id right?
So, I thought, as soon as the user passes the "gate", I deduce his username and create the user from it, storing it in my database, which works for Laravel, doing this.
if(isset($_SERVER)) { if ( array_key_exists( 'PHP_AUTH_USER', $_SERVER ) ) { $agent = $_SERVER['PHP_AUTH_USER']; //Request::server('PHP_AUTH_USER') } $user = User::create([ 'username' => $agent, ]); }
But this makes the user every time the user refreshes the page! But without going further, what is the best way to do this?
Note I know that Laravel has basic auth out of the box, but this will not work because the user is not yet in my database. I need to create them first as above.