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
good post
Thank you alexa