PHP code example of moneo / laravel4-authorization
1. Go to this page and download the library: Download moneo/laravel4-authorization library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
moneo / laravel4-authorization example snippets
namespace App\Providers;
use App\Policies\UserPolicy;
use Moneo\Authorization\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
User::class => UserPolicy::class,
];
public function boot()
{
$this->registerPolicies();
}
}
class UserController {
use \Moneo\Authorization\Foundation\Auth\Access\AuthorizesRequests;
public function store(User $user) {
$this->authorize(UserPolicy::UPDATE, $user);
}
}
namespace App\Policies;
use Moneo\Authorization\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
const UPDATE = 'update';
/**
* Determine whether the user can view the model.
*
* @param User $user
* @return mixed
*/
public function update(User $user, User $authenticatedUser)
{
return $authenticatedUser->isAdmin() || $user->id === $authenticatedUser->id;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.