diff --git a/README.md b/README.md index 4f83f50..5dc7b88 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ composer require jamesmills/eloquent-uuid In order to use this trait, your **schema** must be something like: -``` +```php first(); + if (! $user) { + // Do something else... + } +}); +``` +```php +input('uuids'); + + // Try to get the Users + $users = App\User::withUuids($uuids)->all(); + + // Handle the delete and return + $users->delete(); +}); +``` \ No newline at end of file diff --git a/src/HasUuidTrait.php b/src/HasUuidTrait.php index eb0170a..aa8956d 100644 --- a/src/HasUuidTrait.php +++ b/src/HasUuidTrait.php @@ -24,4 +24,28 @@ public static function findByUuidOrFail($uuid) { return self::whereUuid($uuid)->firstOrFail(); } + + /** + * Eloquent scope to look for a given UUID + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param String $uuid The UUID to search for + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeWithUuid($query, $uuid) + { + return $query->where('uuid', $uuid); + } + + /** + * Eloquent scope to look for multiple given UUIDs + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param Array $uuids The UUIDs to search for + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeWithUuids($query, Array $uuids) + { + return $query->whereIn('uuid', $uuids); + } }