Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ryank30's avatar

laravel\cashier\webhookcontroller problem in Laravel 5.1

I have a line of code for handling cachier in my routes.php file below.

Route::post('stripe/webhook', 'Laravel\Cashier\WebhookController@handleWebhook');

As you suspected, it has been failing. I have been receiving the email from stripe saying that the webhook is failing.

I checked out a discussion regarding this posted 4 months ago (https://laracasts.com/discuss/channels/general-discussion/l5-problem-routing-to-cashiers-webhook-controller). However I don't see any clear solutions yet.

I went and found the location of webhookcontroller. It was under vendor/laravel/cashier/src/Laravel/Cashier. Laravel can't recognize it since it's not under app/http/controller folder. So I added a backslash in front of the name space in routes.php like below. And created a test route.

Route::post('stripe/test', '\Laravel\Cashier\WebhookController@testHere');

Now, I get an error message saying that they can't find the method 'testHere'. This indicates that the route doesn't go to the right controller.

It would be appreciated if you have any solutions or any example or any successful tutorials that you know of.

Some says that they created their own webhook handler controller. If you successfully created one, could you share it with me please?

Thanks,

0 likes
1 reply
ryank30's avatar

Hi Guys,

I just have figured out this issue. I just wanted to share this with you. I hope this is helpful to you.

  1. install Laravel 5.1

  2. add this line of code below: "laravel/cashier": "~4.0"
    in require section of composer.json file.

  3. run "composer update" through cmd or ssh terminal

  4. add this line of code on your routes.php file below: Route::post('stripe/webhook', '\Laravel\Cashier\WebhookController@handleWebhook'); The important thing in this step is that you make sure you add a backslashe infront of Laravel. Because, if you don't add it, laravel will automatically try to access from app\http\controllers folder.

  5. add your webhook url to your stripe account which can be found from 1. your account -> 2. account settings -> 3. webhooks. You can add the url from there. Please make sure you choose test mode unless you are putting it live right away.

  6. Important!! You have to add except to csrf middleware since stripe doesn't pass csrf token. First, you go to VerifyCsrfToken file which is located in app/Http/Middleware. Second add this: 'strip/*', into the except array. So it's going to look like this:

    protected $except = [ 'stripe/*', ];

  7. You can go back to stripe settings page and test it by clicking "send test webhook" button.

If you see "success" message, you are good to go. That's it!

Please or to participate in this conversation.