Skip to content

Instantly share code, notes, and snippets.

@pirey
Created October 27, 2023 16:56
Show Gist options
  • Save pirey/a6305e0fc02dd344fa0260998ce5fd33 to your computer and use it in GitHub Desktop.
Save pirey/a6305e0fc02dd344fa0260998ce5fd33 to your computer and use it in GitHub Desktop.
Personal laravel notes

laravel version: 10

authorization

policy

  • -> authorization logic for model
  • -> auto detected if following naming convention, User -> UserPolicy
  • $request->user()->can('update', $post)
  • $request->user()->cannot('create', Post::class)
  • $this->authorize('update', $post);
  • $this->authorizeResource(Post::class, 'post');

gate

  • -> manual version of policy
  • Gate::allows('update-post', $post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment