LaravelPhp

Important laravel Sentinel Helper functions

Important laravel Sentinel Helper functions

Laravel
408Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, Important laravel Sentinel Helper functions. I am doing with laravel first time in my website. Laravel is one of the top php mvc framework.

Here are the Important laravel Sentinel Helper functions and you can add these Sentinel Helper functions into your laravel helper.php file:

/**
* Return current user id
*/
function getUserId() {
if(Sentinel::check())
return Sentinel::getUser()->id;
}

/**
* Check user role
*/
function checkRole($role) {
if(Sentinel::check()){
if(Sentinel::inRole($role) && Session::get(‘activeRole’) == $role) {
return true;
}
}
return false;
}

/**
* get user role first
*/
function getUserRole() {
$roles = Sentinel::findById(getUserId())->roles;
foreach ($roles as $role) {
return $role->slug;
}
}

/**
* get active role from session
*/
function getActiveRole() {
if(Session::has(‘activeRole’))
return Session::get(‘activeRole’);
}

/**
* Get all user with admin role
*/
function getAdmins() {
$role = Sentinel::findRoleBySlug(‘admin’);
$users = $role->users()->with(‘roles’)->get();
return $users;
}

There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

2 Comments

Leave a Reply