In this episode, we’re focusing on cleaning up how we check user permissions in our Blade templates using the @can
directive. The main idea here is that we want to make sure all our permission checks go through our policies instead of directly referencing specific permissions. This keeps things more organized, centralized, and easier to update in the future.
We start by searching through our codebase for places where we've used the @can
directive and notice that in some spots, we’re checking permission strings directly (like can:invite to team
). That’s not ideal, so we update these to reference policy methods (like can:inviteToTeam, $team
).
Along the way, we spot situations where a policy method doesn’t exist yet (like viewTeamMembers
), so we take a moment to add those to our policy classes, even if all they do is check a permission for now. This way, if our permission logic ever needs to change, we only have to update the policy.
After switching everything over and testing it out in the UI, we confirm that the functionality stays the same, but now our permission system is much more maintainable. Any future tweaks to authorization will be reflected everywhere automatically, keeping our code consistent and reliable!