Categories

Saturday, July 20, 2024
#919814419350 therichposts@gmail.com
LaravelPhp

Important laravel Sentinel Helper functions

Laravel 7.2 routing with route group auth guard check with prefix

Important laravel Sentinel Helper functions

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

therichpost
the authortherichpost
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 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

2 Comments

Leave a Reply

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