Let's take this simple statement:
PHP Code:
$myarray = $this->asArray()->where('id',$id)->first();
If it finds a record it will return a collection of key/value pairs.
I'd like to know if there is a way to make it return a collection of keys with empty values when it doesn't find a matching record instead of return null.
Thanks!
I figured it out. Not as straight forward as I wanted but it works finely. Here it goes in case someone else needs it:
PHP Code:
public static function getEmptyRecord($table) {
$db = \Config\Database::connect();
$builder = $db->query("SHOW COLUMNS FROM $table");
$result = [];
foreach (json_decode(json_encode($builder->getResult()),true) as $row)
$result[$row['Field']] = '';
return $result;
}
Recovering the wasted time...