Custom Laravel Valet Driver
Valet is a PHP Minimalist’s dream come true. It allows you to build PHP-based applications locally on your Mac without having to install Apache or NGINX. Visit the Laravel Valet site.
A custom Valet Driver lets you configure how you application is served. The documentation being quite minimalist itself and was a source of frustration as I tried to get some .htaccess-like behaviour. After some experimentation, I’d like to share my custom driver configuration that achieves the following:
- Serves static (non-php) file such as .js, .css and images.
- Looks for a child index.php file when you request URLs like /app/admin/.
- Falls back to default file such as a 404 page or a catch-all URL for building RESTful endpoints like /api/contacts.
How to create/find/edit your Valet Driver file
The path to Valet Drivers is hidden on your Mac so open Terminal and run the following:
defaults write com.apple.finder AppleShowAllFiles YES
You can then browse to the following directory using Finder to locate existing or create new Valet drivers (Thanks to Kevin Batdorf for pointing out that I didn’t have this paragraph earlier).
Then hold down the ALT/OPTION key and right-click the Finder icon in the dock to select “relaunch”. You can now see hidden files. To hide, use the following command and relaunch your Finder again.
defaults write com.apple.finder AppleShowAllFiles NO
Securing your valet site
Your browser’s inspector will give you tonnes of warnings because your valet site is not protected by SSL. The solution is to simply use these commands:
valet secure mysite
valet unsecure mysite
Have improvements? Add your comments here.
Mikk Pokk (Valet driver for Opencart)