Skip to content

Instantly share code, notes, and snippets.

@jeffochoa
Last active November 19, 2018 06:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffochoa/c42f7141af1c5ab1644afe9cd39f61c5 to your computer and use it in GitHub Desktop.
Save jeffochoa/c42f7141af1c5ab1644afe9cd39f61c5 to your computer and use it in GitHub Desktop.
Laravel OwnsModel Trait
<?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