New method for consistent data collection.

This commit is contained in:
James Cole
2020-12-02 17:12:58 +01:00
parent cbe046ba07
commit 35c9367819
4 changed files with 57 additions and 20 deletions

View File

@@ -33,6 +33,27 @@ use Log;
trait ConvertsDataTypes
{
/**
* Returns all data in the request, or omits the field if not set,
* according to the config from the request. This is the way.
*
* @param array $fields
*
* @return array
*/
protected function getAllData(array $fields): array
{
$return = [];
foreach ($fields as $field => $info) {
if ($this->has($info[0])) {
$method = $info[1];
$return[$field] = $this->$method($info[0]);
}
}
return $return;
}
/**
* Return date or NULL.
*
@@ -142,7 +163,7 @@ trait ConvertsDataTypes
return null;
}
Log::debug(sprintf('Date object: %s (%s)',$carbon->toW3cString() , $carbon->getTimezone()));
Log::debug(sprintf('Date object: %s (%s)', $carbon->toW3cString(), $carbon->getTimezone()));
return $carbon;
}