Accessing an item from a key value pair object derived from a parent relationship

Solution 1:

Please change the createdBy relationship function with the createdByUser.

here we just change the function name to avoid conflict between column name and relationship name.

public function createdByUser()
{
    return $this->belongsTo(self::class, 'created_by');
}

so now, you can access like

$user->createdByUser->email