Skip to content

Instantly share code, notes, and snippets.

@gpressutto5
Created September 1, 2017 21:16
Show Gist options
  • Save gpressutto5/ee645498a0a66116c9bac3f42212d21a to your computer and use it in GitHub Desktop.
Save gpressutto5/ee645498a0a66116c9bac3f42212d21a to your computer and use it in GitHub Desktop.
Magento 2 Local Driver for Laravel Valet
<?php
class LocalValetDriver extends LaravelValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath.'/pub/index.php') &&
file_exists($sitePath.'/bin/magento');
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
$uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri);
if (file_exists($staticFilePath = $sitePath.'/pub'.$uri)) {
return $staticFilePath;
}
if (strpos($uri, '/static/') === 0) {
$_GET['resource'] = preg_replace('#static/#', '', $uri, 1);
include($sitePath.DIRECTORY_SEPARATOR.'pub/static.php');
exit;
}
if (strpos($uri, '/media/') === 0) {
include($sitePath.DIRECTORY_SEPARATOR.'pub/get.php');
exit;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
return $sitePath.'/pub/index.php';
}
}
@joaolisboa
Copy link

Years later and thanks! This driver works better than the default one. The default Magento 2 driver in Laravel Valet doesn't seem capable of delivering static assets in developer mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment