Skip to content

Commit

Permalink
Merge branch '7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
santigarcor committed Mar 4, 2022
2 parents e7ba002 + b9fee84 commit 8a18c70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"require": {
"php": ">=7.2",
"kkszymanowski/traitor": "^0.2.0",
"kkszymanowski/traitor": "^1.0",
"laravel/framework": "~6.0|~7.0|~8.0|^9.0"
},
"require-dev": {
Expand Down
20 changes: 14 additions & 6 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@
class Helper
{
/**
* Gets the it from an array, object or integer.
* Gets the id from an array, object or integer.
*
* @param mixed $object
* @param string $type
* @return int
*/
public static function getIdFor($object, $type)
public static function getIdFor($object, string $type)
{
if (is_null($object)) {
return null;
} elseif (is_object($object)) {
}

if (is_object($object)) {
return $object->getKey();
} elseif (is_array($object)) {
}

if (is_array($object)) {
return $object['id'];
} elseif (is_numeric($object)) {
}

if (is_numeric($object)) {
return $object;
} elseif (is_string($object)) {
}

if (is_string($object)) {
return call_user_func_array([
Config::get("laratrust.models.{$type}"), 'where'
], ['name', $object])->firstOrFail()->getKey();
Expand Down

0 comments on commit 8a18c70

Please sign in to comment.