Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined array key 1 in LaravelNotificationsDataSource #733

Open
freestyledork opened this issue Feb 20, 2025 · 0 comments
Open

Undefined array key 1 in LaravelNotificationsDataSource #733

freestyledork opened this issue Feb 20, 2025 · 0 comments

Comments

@freestyledork
Copy link

When logging sent emails I ran into an issue where cced emails have a NULL name array value. This was causing a false positive in the ternary setter and throwing an error. @itsgoingd any chance this is easy enough to add without needing a PR?

Before:

	protected function notificationAddressToString($address)
	{
		if (! $address) return;
		if (! is_array($address)) $address = [ $address ];

		return array_map(function ($address) {
			if (! is_array($address)) return $address;

			$email = isset($address['address']) ? $address['address'] : $address[0];
			$name = isset($address['name']) ? $address['name'] : $address[1];

			return $name ? "{$name} <{$email}>" : $email;
		}, $address);
	}

After:

	protected function notificationAddressToString($address)
	{
		if (! $address) return;
		if (! is_array($address)) $address = [ $address ];

		return array_map(function ($address) {
			if (! is_array($address)) return $address;
                        // ----- check array key exists vs has value -----
			$email = array_key_exists('address', $address) ? $address['address'] : $address[0];
			$name = array_key_exists('name', $address) ? $address['name'] : $address[1];

			return $name ? "{$name} <{$email}>" : $email;
		}, $address);
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant