Created
September 2, 2017 02:06
-
-
Save byjml/aab5795038071f4a20d66b70c0f7e6a7 to your computer and use it in GitHub Desktop.
Laravel policy to check if user can follow a user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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