Laravel Valet Supports Custom Per-Site Drivers

Laravel Valet Supports Custom Per-Site Drivers

Laravel Valet is an incredible tool for getting a local development environment running in no time at all.

It’s driver based, and each driver adds support for a different type of application, framework, CMS, etc.

If you’d like to add support for something that doesn’t yet exist, it’s pretty simple to create your own driver, and share it with the community.

While there are a number different drivers out of the box, and even more that exist out there, some of them can make assumptions about how your project will be set up.

For example, the Laravel driver assumes your web root is located in a public directory. If you’ve renamed it to public_html, Valet simply won’t recognize that it’s Laravel.

To remedy this, you can create your own local driver that applies for a single project.

Just follow the steps to create a driver, but name it LocalValetDriver.php and place it in your project’s root directory.

<?php

class LocalValetDriver extends LaravelValetDriver
{
    public function serves()
    {
        return true;
    }
    public function frontControllerPath($sitePath, $siteName, $uri)
    {
        return $sitePath.'/public_html/index.php';
    }
}

You can either extend the base ValetDriver class to write the full driver from scratch or extend an existing driver and just override what you need.


Filed in: News / Valet


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Software Engineer - LAMP/PHP/MySQL/Laravel
Los Angeles / Remote
Ranker
Senior PHP/Laravel Developer: Your Dream Work Environment
Remote
iPhone Photography School
In-house Laravel Developer.
Gold Coast / Australia
MXstore
Laravel Developer
Oak Brook, IL
Tidal Commerce
Senior Backend Engineer
Santa Monica only
Saatchi Art
Senior Laravel Developer
San Francisco
Stitch Labs
Senior Software Developer
South Jordan, UT
Lendio