spatie / laravel-webhook-client

Receive webhooks in Laravel apps
https://freek.dev/1383-sending-and-receiving-webhooks-in-laravel-apps
MIT License
985 stars 146 forks source link

Another route has already been assigned name error when trying to create multiple endpoints for the same app #211

Closed hanicab closed 5 months ago

hanicab commented 5 months ago

Hello,

My application should have 1 endpoint that accepts GET and POST methods.

The POST method for receiving data, and the GET method for health checks.

But when I tried doing that by adding the lines above to my route.php file, I got an error.

Route::webhooks('webhook-url', 'app-1', 'get');
Route::webhooks('webhook-url', 'app-1', 'post');

The error is :

Unable to prepare route [webhook-url] for serialization. Another route has already been assigned name [webhook-client-app-1].

Have you an idea how to resovle this issue ?

Thanks

ryanlholt commented 5 months ago

Hi @hanicab, are you on the latest version (3.3.1) of the package? A PR got merged earlier today that should have fixed this issue.

hanicab commented 5 months ago

@ryanlholt You are right, the bug is fixed when updated to the latest version

Thank you very much !

I think it was better to add the method name as suffix instead of a random string, to be able to call the route by its name inside the app (from views ..etc).

example : ->name("webhook-client-{$name}-{$method}");

ryanlholt commented 5 months ago

@hanicab Yeah I'm not sure if the endpoints were meant to be used like that since that portion is undocumented. We actually ran into this issue when using the same config for multiple endpoints and not due to using different methods for the same endpoint. You may be able to use some combination of Laravel's underlying route functions to find the name of the route you need.

freekmurze commented 5 months ago

Fixed in the latest version.