My custom helper class is this:
Located in app/bootstrap/ACL.php
class ACL {
public function __construct(){
//Get user from session
//Get user permission array
}
public function isAllowed($key){
return 'calling from ACL class';
}
}
Now, I need to access this ACL class inside all of the project controllers. So
I require_once 'ACL.php';
in my app.php file.
Then inside my controller I can do the following:
class UserController extends Controller {
public function editDetails() {
$acl = new \ACL();
echo $acl->isAllowed('edit-details');
//below is the code to edit details
}
}
This code works, but I feel there should be a Laravel 5 proper way to do this. I want to know:
1) Is this approach OK or is there a better way to achieve this?
2) Without doing $acl = new \ACL();
in every controller, can I use a global variable?
Or something like this ACL::isAllowed('edit-details');
3) How can I run $acl->isAllowed('edit-details')
condition in Blade templates properly?
Thanks a lot!