Laravel Herd

Documentation for macOS

Custom Drivers

#
Custom Drivers

You can extend Herd with your own drivers to support custom setups of supported frameworks or to add new frameworks that Herd doesn't support out of the box.

Herd internally leverages a version of Laravel Valet for serving sites and includes all drivers that Valet provides. These drivers are a good start when creating your own custom driver, and it often makes sense to extend them than starting from scratch.

Place your custom driver in the related valet directory on your machine and Herd loads it automatically.

–/Library/Application Support/Herd/config/valet/Drivers

#
Custom Laravel Driver

This example of a custom driver extends the existing Laravel Driver and modifies it to serve the application from a web instead of the public directory.

 
namespace Valet\Drivers\Custom;
 
use Valet\Drivers\LaravelValetDriver;
 
class CustomLaravelValetDriver extends LaravelValetDriver
{
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/web/index.php') &&
file_exists($sitePath.'/artisan');
}
 
/**
* Determine if the incoming request is for a static file.
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
{
if (file_exists($staticFilePath = $sitePath.'/web'.$uri)
&& is_file($staticFilePath)) {
return $staticFilePath;
}
 
$storageUri = $uri;
 
if (strpos($uri, '/storage/') === 0) {
$storageUri = substr($uri, 8);
}
 
if ($this->isActualFile($storagePath = $sitePath.'/storage/app/public'.$storageUri)) {
return $storagePath;
}
 
return false;
}
 
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
if (file_exists($staticFilePath = $sitePath.'/web'.$uri)
&& $this->isActualFile($staticFilePath)) {
return $staticFilePath;
}
 
return $sitePath.'/web/index.php';
}
}