Describe the bug
This is possibly an isolated issue.
Earlier today I tried to configure LdapRecord-Laravel.
As soon as I tried to login with a user a TypeError exception was thrown with the following text:
_Argument 1 passed to LdapRecord\Models\Model::serializeDate() must implement interface DateTimeInterface, null given, called in C:\Users\bruno.martins\source\repos\outono\vendor\directorytree\ldaprecord\src\Models\Concerns\HasAttributes.php on line 105_
Se screenshot below

To fix this I dug arround a bit and found that some of the user attributes, like _'lockouttime'_ and _'lastlogoff_ were set to "0", and when put throught the _$this->asDateTime()_ were being returned as null.
Following my discovery I added a simple check, see below:
No fix:
protected function addDateAttributesToArray(array $attributes)
{
foreach ($this->getDates() as $attribute => $type) {
if (!isset($attributes[$attribute]) || $attributes[$attribute] === 0) {
continue;
}
$date = $this->serializeDate(
$this->asDateTime($type, $attributes[$attribute])
);
$attributes[$attribute] = Arr::wrap($date);
}
return $attributes;
}
Fix:
protected function addDateAttributesToArray(array $attributes)
{
foreach ($this->getDates() as $attribute => $type) {
if (!isset($attributes[$attribute])) {
continue;
}
$attributeAsDateTime = $this->asDateTime($type, $attributes[$attribute]);
if ($attributeAsDateTime === null) {
continue;
}
$date = $this->serializeDate(
$attributeAsDateTime
);
$attributes[$attribute] = Arr::wrap($date);
}
return $attributes;
}
After this, I could login with a user and use the app, again, I do not know if this is an isolated issue or not, If it's not, I am more than happy to file a merge request and tweak the code for a fix.
Thanks!
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The user is logged in and created in the database
Environment (please complete the following information):
Hi @BrunMartins, this was just reported here as well: #117
I'm fixing this now -- however I'm trying to determine what timestamp values you both may have for the whencreated and whenchanged LDAP properties which is causing the failure of conversion?
Fixed, release coming shortly, thanks!
Sorry, I only saw your email a moment ago, glad it is fixed!
No worries @BrunMartins! @brinkonaut supplied me with the value I needed to determine the cause. Appreciate the reply!
I'm creating a new release in a couple minutes -- run composer update and you'll be good to go! 馃帀