Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12870205
FindableByAttribute.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
761 B
Referenced Files
None
Subscribers
None
FindableByAttribute.php
View Options
<?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-php
Expires
Mon, Nov 17, 15:46 (17 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3167182
Default Alt Text
FindableByAttribute.php (761 B)
Attached To
Mode
rGROVE Auth Grove
Attached
Detach File
Event Timeline
Log In to Comment