Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F52700213
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
989 B
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Services/FindableByAttribute.php b/app/Services/FindableByAttribute.php
new file mode 100644
index 0000000..92697a7
--- /dev/null
+++ b/app/Services/FindableByAttribute.php
@@ -0,0 +1,21 @@
+<?php namespace AuthGrove\Services;
+
+trait FindableByAttribute {
+ /**
+ * Finds an object by the specified attribute and value
+ *
+ * @param string $attribute The attribute to find
+ * @param string $value The value the object should have for the specified attribute to match
+ * @return Model|null If the object has been found, an instance of the class. Otherwise, null
+ *
+ * e.g. User::findBy('username', 'quux')
+ *
+ * If the attribute isn't unique, this method will return the first object found.
+ */
+ static function findBy ($attribute, $value) {
+ $method = 'static::where' . ucfirst($attribute);
+ $object = call_user_func($method, $value)
+ ->first(['*']);
+ return $object;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Oct 6, 02:37 (42 m, 42 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4152222
Default Alt Text
(989 B)
Attached To
Mode
rGROVE Auth Grove
Attached
Detach File
Event Timeline
Log In to Comment