From de5308d4f2e0d70107e78e1a2d69b905b9789fd5 Mon Sep 17 00:00:00 2001 From: Jon Park Date: Wed, 3 May 2017 16:55:24 +0100 Subject: [PATCH 1/2] Adding scopes to help with querying --- src/HasUuidTrait.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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); + } } From 5f5c86768a0f38d921e73ba363c483b939e5dbe9 Mon Sep 17 00:00:00 2001 From: Jon Park Date: Wed, 3 May 2017 17:07:14 +0100 Subject: [PATCH 2/2] Updating with scope examples --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) 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