How to use Stripe CLI with Laravel Valet to listen for events | RJS

How to use Stripe CLI with Laravel Valet to listen for events

Use the Stripe CLI with Laravel Valet to listen to webhooks locally.

Ralph J. Smit Laravel & PHP-developer.

Stripe is a terrific company for developers. Their API's and developer-facilities are absolutely the best. One of those awesome things Stripe offers, is the Stripe CLI. This is a Command-line tool which you can use on your local device to test and simulate webhooks easily.

However, the Stripe CLI doesn't immediately work with Laravel Valet. Valet is an awesome tool as well, but sometimes not all awesomeness is able to work together.

After some googling and debugging, I luckily found an easy fix to get the Stripe CLI working with Laravel Valet.

1. Update your /etc/hosts file

For this example, let's say that our Laravel Valet domain is called stripe.test.

To make the Stripe CLI work with Laravel Valet, we need to make a little change to your hosts file. If you haven't heard of this before, the hosts-file is a small file on your computer that you can use to map a domain to a specific IP. So it basically allows you to override certain DNS-settings.

Anyway, that complex talk doesn't matter now. You should open your hosts file from /etc/hosts. This file needs sudo-access, so the easiest way is to edit it with the Nano-editor.

sudo nano /etc/hosts

If you don't like the Nano-editor, you can open the file in a text-editor as well:

sudo open /etc/hosts

Next, you should add the following rule to your /etc/hosts file (substitute stripe.test for your domain): stripe

Next, save the file.

2. Flush the DNS cache

Usually, such DNS/IP-settings are cached for a while, so that your computer will be faster. To flush the DNS-cache, run:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

You might also need to clear your browser cache/cookies.

3. Use Stripe CLI with Laravel Valet ⚡️

Now you are ready to use the Stripe CLI with Laravel Valet. For example, if you're using Laravel Cashier with Stripe, you can use the following command to forward webhooks to your local application as well:

stripe listen --forward-to https://stripe.test/stripe/webhook

Wrapping up

As you've seen, it really isn't difficult to get the Stripe CLI to work with Laravel Valet. However, when I encountered this the first time, it took me a while to figure it all out. Happy developing!

Published by Ralph J. Smit on in Stripe.

Hey!👋 Like what you read?

Every now and then I send out a newsletter with new articles, tutorials and packages, mainly related to PHP in general and Laravel.

Subscribe to the newsletter and stay up to date with all things Laravel, Tailwind, WordPress & PHP. Never miss an update.🙋‍