getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->class != get_class($model) || ! empty($method->getParameters()) || in_array($method->getName(), $excludedMethods) || str_starts_with($method->getName(), 'boot') ) { continue; } try { $return = $method->invoke($model); if ($return instanceof Relation) { $relationships[$method->getName()] = [ 'type' => (new ReflectionClass($return))->getShortName(), 'model' => (new ReflectionClass($return->getRelated()))->getName(), ]; } } catch (\Throwable $e) { } } return $relationships; } /** * Available relationships for the model. * * @var array */ public static $availableRelations = []; public static function getRelationshipsNames($needInitialize = false, $outputFormat = 'camelCase'): array { if ($needInitialize) { self::setAvailableRelations(); } $ret = array_keys(self::$availableRelations); switch ($outputFormat) { case 'camelCase': $ret = array_map(function ($val) { return lcfirst($val); }, $ret); break; case 'snakeCase': case 'snake_case': $ret = array_map(function ($val) { return strtolower(preg_replace('/(?