Laravel 7.2 routing with route group auth guard check with prefixLaravel 7.2 routing with route group auth guard check with prefix

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

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

2 thoughts on “Important laravel Sentinel Helper functions”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.