Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. protected $policies = [
  2.  
  3. 'AppModel' => 'AppPoliciesModelPolicy',
  4. User::class => UserPolicy::class,
  5. Insured::class => InsuredPolicy::class
  6. ];
  7.  
  8. public function boot(GateContract $gate)
  9. {
  10. $this->registerPolicies($gate);
  11. }
  12.  
  13. use HandlesAuthorization;
  14.  
  15. protected $user;
  16.  
  17. public function __construct(User $user) {
  18. $this->user = $user;
  19. }
  20.  
  21. public function index(User $user) {
  22. $is_authorized = $user->hasRole('Admin');
  23. return $is_authorized;
  24. }
  25.  
  26. public function show(User $user, User $user_res) {
  27.  
  28. $is_authorized = ($user->id == $user_res->id);
  29. return $is_authorized;
  30. }
  31.  
  32. public function store() {
  33. $is_authorized = $user->hasRole('Admin');
  34. return true;
  35. }
  36.  
  37. public function index()
  38. {
  39. //temporary authentication here
  40. $users = User::all();
  41. $this->authorize('index', User::class);
  42. return $users;
  43. }
  44.  
  45. public function show($id)
  46. {
  47. $user = User::find($id);
  48. $this->authorize('show', $user);
  49. return $user;
  50. }
  51.  
  52. public function store(Request $request) {
  53.  
  54.  
  55. $user = new User;
  56. $user->name = $request->get('name');
  57. $user->email = $request->get('email');
  58. $user->password = Hash::make($request->get('password'));
  59.  
  60.  
  61. $user->save();
  62.  
  63. return $user;
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement