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

NotificationWatcher formatNotifiable TypeError #1375

Closed
yangjisen opened this issue Aug 14, 2023 · 5 comments
Closed

NotificationWatcher formatNotifiable TypeError #1375

yangjisen opened this issue Aug 14, 2023 · 5 comments

Comments

@yangjisen
Copy link

Telescope Version

4.16.0

Laravel Version

10.18.0

PHP Version

8.1.4

Database Driver & Version

8.0.27

Description

When the incoming $notifiable is an array, the error is: NotificationWatcher formatNotifiable TypeError

private function formatNotifiable($notifiable)
{
if ($notifiable instanceof Model) {
return FormatModel::given($notifiable);
} elseif ($notifiable instanceof AnonymousNotifiable) {
$routes = array_map(function ($route) {
return is_array($route) ? implode(',', $route) : $route;
}, $notifiable->routes);
return 'Anonymous:'.implode(',', $routes);
}
return get_class($notifiable);
}

Should an is_array($notifiable) be added before return get_class($notifiable) in the formatNotifiable method?

Steps To Reproduce

step1: Generating Notifications php artisan make:notification InvoicePaid
step2: Using The Notification Facade

	$notifiables = [[
		'title' => 'title',
		'text' => 'text',
	]];

	Notification::send($notifiables, new InvoicePaid($invoice));

Now use the facade to send messages, and when the incoming parameter $notifiables is an array, the class NotificationWatcher on method formatNotifiable of the telescope will report an error: "NotificationWatcher formatNotifiable TypeError" when checking the type because $notifiables is not a class but an array, using get_class($notifiable)

@crynobone crynobone added the bug label Aug 14, 2023
@driesvints
Copy link
Member

I'm not sure what the proper solution here is but would appreciate a PR if you can figure something out, thanks!

@github-actions
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@yangjisen
Copy link
Author

I'm not sure what the proper solution here is but would appreciate a PR if you can figure something out, thanks!

I made the instanceof judgment, I think we should add some other type judgment, View the Notification facade * @method static void send(\Illuminate\Support\Collection|array|mixed $notifiables, mixed $notification) Supported type, I'm not sure what type formatNotifiable should return in array, but is it now a string

@driesvints
Copy link
Member

Hi there, right now we don't document the usage of notifications like this. Therefor, I don't think we can consider this as supported, sorry. Please use regular class based notifications, thanks.

@yangjisen
Copy link
Author

Hi there, right now we don't document the usage of notifications like this. Therefor, I don't think we can consider this as supported, sorry. Please use regular class based notifications, thanks.

I think it's rude to closed issues that way, and I don't know why that is, According to Notification ::send(\Illuminate\Support\Collection|array|mixed $notifiables, mixed $notification) is a $notifiables that supports incoming array types. Is it not supported because it is an error for me to call send incoming array?

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

3 participants