Skip to content

Instantly share code, notes, and snippets.

@mra-dev
Created March 5, 2023 01:23
Show Gist options
  • Save mra-dev/0b583d05536775cce795ecc04f8afc17 to your computer and use it in GitHub Desktop.
Save mra-dev/0b583d05536775cce795ecc04f8afc17 to your computer and use it in GitHub Desktop.
Laravel Valet Driver - Serving Html Files with Pretty URL (I Used it with a Quasar Project)
<?php
class SampleValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
if (file_exists($sitePath . '/index.html')) {
return true;
}
return false;
}
/**
* 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)
{
// A non-PHP static file is found.
if (file_exists($staticFilePath = $sitePath . $uri) && !is_dir($staticFilePath) && pathinfo($staticFilePath)['extension'] != '.php') return $staticFilePath;
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)
{
$_SERVER['SCRIPT_NAME'] = '/index.html';
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.html';
$_SERVER['X_PATH_INFO'] = $uri;
$_SERVER['X_REWRITE'] = 1;
return $sitePath.'/index.html';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment