Skip to content

Instantly share code, notes, and snippets.

@programarivm
Last active December 28, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programarivm/434e1c1f1b873e805e43a2ec69472189 to your computer and use it in GitHub Desktop.
Save programarivm/434e1c1f1b873e805e43a2ec69472189 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Requests;
use App\Acl;
use Illuminate\Foundation\Http\FormRequest;
abstract class AbstractAuthorizedFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$role = auth()->user()->getAttributes()['role'];
$resource = substr($this->route()->getActionName(), strrpos($this->route()->getActionName(), '\\') + 1);
return \App\Acl::isAuthorized($role, $resource);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment