Last active
November 19, 2018 06:07
-
-
Save jeffochoa/c42f7141af1c5ab1644afe9cd39f61c5 to your computer and use it in GitHub Desktop.
Laravel OwnsModel Trait
This file contains 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 | |
trait OwnsModel { | |
/** | |
* Determine whether this model owns the given model. | |
* Usage: if ($user->owns($article)) { ... | |
* | |
* @param Model $model | |
* @return bool | |
*/ | |
public function owns(Model $model) | |
{ | |
return $this->id === $model->{$this->getForeignKey()}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment