how can I get & register the logged-in user ID in a table, with October cms
thank you in advance!
You can simply use this Auth facade
to get current logged-in user
// =====> forntend
// Returns the signed in user
$user = Auth::getUser();
// now use
// $user->id in your code
// =====> backend
use BackendAuth;
$user = BackendAuth::getUser();
// now use
// $user->id in your code
you need to add beforeSave event method to you model in which you want to log be user id also in addition you need to add this log_be_user_id
field to your database table
use BackendAuth;
public function beforeSave() {
// check if we are in backend
if(App::runningInBackend()) {
// we assign the be logged in user id
$user = BackendAuth::getUser();
$this->log_be_user_id = $user->id;
}
}
if any doubts please comment