Skip to content

Commit

Permalink
Change the Ownable interface to accept the owner in the ownerKey method
Browse files Browse the repository at this point in the history
Allows to receive the owner in the ownerKey method in case the owner key check  changes depending of the type of the owner.
  • Loading branch information
santigarcor committed Jul 26, 2017
1 parent 82c850d commit b68e9ea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Laratrust/Contracts/Ownable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ interface Ownable
/**
* Gets the owner key value inside the model or object.
*
* @param mixed $owner
* @return mixed
*/
public function ownerKey();
public function ownerKey($owner);
}
2 changes: 1 addition & 1 deletion src/Laratrust/Traits/LaratrustUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public function syncPermissions($permissions = [], $team = null)
public function owns($thing, $foreignKeyName = null)
{
if ($thing instanceof \Laratrust\Contracts\Ownable) {
$ownerKey = $thing->ownerKey();
$ownerKey = $thing->ownerKey($this);
} else {
$className = (new \ReflectionClass($this))->getShortName();
$foreignKeyName = $foreignKeyName ?: Str::snake($className . 'Id');
Expand Down
2 changes: 1 addition & 1 deletion tests/LaratrustUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ public function publicMagicCan($method) {

class OwnableObject implements Ownable
{
public function ownerKey()
public function ownerKey($owner)
{
return 1;
}
Expand Down

0 comments on commit b68e9ea

Please sign in to comment.