Skip to content

Instantly share code, notes, and snippets.

@byjamaljama
Created September 2, 2017 02:06
Show Gist options
  • Save byjamaljama/aab5795038071f4a20d66b70c0f7e6a7 to your computer and use it in GitHub Desktop.
Save byjamaljama/aab5795038071f4a20d66b70c0f7e6a7 to your computer and use it in GitHub Desktop.
Laravel policy to check if user can follow a user.
<?php
namespace App\Policies;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
/**
* Determine whether the logged in user can follow this user.
*
* Usage in blade:
*
* @can('follow', $user)
* <button>Follow</button>
* @endcan
*
* @param \App\User $user
* @param \App\User $profile
* @return bool
*/
public function follow(User $user, User $profile)
{
return ($user->id !== $profile->id && ! $user->followed($profile->id) && ! $profile->blocked($user->id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment