Ad
Get & Register The Logged-in User ID October Cms
how can I get & register the logged-in user ID in a table, with October cms
thank you in advance!
Ad
Answer
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
In back-end if you want to add current logged in BE-User id then
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
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page
Ad