1
votes

I'm trying to implement slack notifications on my laravel project.

Inside my controller I call:

$user->notify(new WorkAdded());

Here the WorkAdded class

public function __construct()
{
    //
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['slack'];
}


/**
 * Get the Slack representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return SlackMessage
 */
public function toSlack($notifiable)
{
    return (new SlackMessage)
                ->content('TEST');
}

In the User class I've added:

use Notifiable;

public function routeNotificationForSlack($notification)
{
    return 'https://hooks.slack.com/services/...';
}

But when I call the notify function I get the following error:

Type error: Too few arguments to function App\User::routeNotificationForSlack(), 0 passed in /Applications/MAMP/htdocs/gest/vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php on line 30 and exactly 1 expected

1
When routeNotificationForSlack() is called, you're not passing a parameter with it, that's why you're getting an error that says 0 passed, expected 1.user5283119

1 Answers

0
votes

If you're using Laravel 5.5 or below the routeNotificationFor{driver} methods aren't passed a $notification instance.

Changing your method to the following should be all you need:

public function routeNotificationForSlack()
{
    return 'https://hooks.slack.com/services/...';
}

When using the Laravel docs, it's always a good idea to change the dropdown in the top right of the screen to be the version of Laravel you're using.