Skip to content

Commit

Permalink
Add scope and find methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kilrizzy committed Nov 14, 2017
1 parent bbf914e commit 8fb4def
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```
8 changes: 8 additions & 0 deletions src/Traits/HasUUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

0 comments on commit 8fb4def

Please sign in to comment.