Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected $policies = [
- 'AppModel' => 'AppPoliciesModelPolicy',
- User::class => UserPolicy::class,
- Insured::class => InsuredPolicy::class
- ];
- public function boot(GateContract $gate)
- {
- $this->registerPolicies($gate);
- }
- use HandlesAuthorization;
- protected $user;
- public function __construct(User $user) {
- $this->user = $user;
- }
- public function index(User $user) {
- $is_authorized = $user->hasRole('Admin');
- return $is_authorized;
- }
- public function show(User $user, User $user_res) {
- $is_authorized = ($user->id == $user_res->id);
- return $is_authorized;
- }
- public function store() {
- $is_authorized = $user->hasRole('Admin');
- return true;
- }
- public function index()
- {
- //temporary authentication here
- $users = User::all();
- $this->authorize('index', User::class);
- return $users;
- }
- public function show($id)
- {
- $user = User::find($id);
- $this->authorize('show', $user);
- return $user;
- }
- public function store(Request $request) {
- $user = new User;
- $user->name = $request->get('name');
- $user->email = $request->get('email');
- $user->password = Hash::make($request->get('password'));
- $user->save();
- return $user;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement