diff --git a/README.md b/README.md index 6859917..f501416 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,15 @@ class Project extends Model If your column name is not "uuid", simply add a new property to your model named "uuidFieldName": protected $uuidFieldName = 'unique_id'; + +This trait also adds a scope: + +``` +\App\Project::byUUID('uuid')->first(); +``` + +And static find method: + +``` +\App\Project::findByUUID('uuid') +``` \ No newline at end of file diff --git a/src/Traits/HasUUID.php b/src/Traits/HasUUID.php index a6ebe44..a9ab43e 100644 --- a/src/Traits/HasUUID.php +++ b/src/Traits/HasUUID.php @@ -24,4 +24,12 @@ public static function generateUUID(){ return \Uuid::generate()->string; } + public function scopeByUUID($query, $uuid){ + return $query->where($this->getUUIDFieldName(),$uuid); + } + + public static function findByUuid($uuid){ + return static::byUUID($uuid)->first(); + } + } \ No newline at end of file