Download the PHP package psecio/propauth-provider without Composer
On this page you can find all versions of the php package psecio/propauth-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download psecio/propauth-provider
More information about psecio/propauth-provider
Files in psecio/propauth-provider
Package propauth-provider
Short Description A Laravel provider for adding PropAuth checking to Blade templates
License MIT
Homepage https://github.com/psecio/propauth-provider.git
Informations about the package propauth-provider
Policy Template (Blade) Service Provider for PropAuth
This service provider, for Laravel 5+ based applications, introduces the ability to perform PropAuth evaluation checks on the current user against pre-defined policies.
Usage
To use this provider, update your Laravel app's app.php
configuration's "providers" section to pull in this provider:
What else is required
This library requires two things:
- That you have the PropAuth functionality installed
- That you have policies defined in your application according to this setup: Security Policy Evaluation in Laravel with PropAuth
Essentially, the requirement is that there's another service provider (in the example it's the PolicyServiceProvider
) that defines your policies in a singleton named "policies" and returns an enforcer object. For example, you could put this in app/providers/PolicyServiceProvider.php
:
This just defines the one policy, can-edit
, where it checks the current user (pulled via \Auth::user()
) to see if they have a username
property of "ccornutt". With this in place, you can then use the service provider in this repo to add checks to your Blade templates.
For example, to use the can-edit
check above you could use something like this:
The two methods exposed are @allows
and @denies
with a required first parameter. You can also pass in optional parmeters if your PropAuth
checks are more complex and use the closures handling. So, if your policy is defined like this:
You need to pass in a value/object for $post
in the can-delete
closure. You can do this by giving the @allows
/@denies
more optional parameters: