我使用 Laravel Valet 在本地为多个 Laravel、WordPress 和 vanilla PHP 应用程序提供服务。
我有一个特定的应用程序是 vanilla PHP,我可以从http://myapplication.test通过 Valet 访问它
这个应用程序有一个 /public/index.php 文件,当我转到测试 URL 时,它会自动神奇地显示,因为 Valet 知道要查看 public 目录。
我遇到的问题是,当我放置一个 /public/test.php 文件并尝试通过访问http://myapplication.test/test.php来访问它时……它不提供该文件。相反,我被迫去http://myapplication.test/public/test.php
有什么办法可以解决这个问题吗?
这导致我在我的代码库中做了一个丑陋的重复工作。在实时项目中,转到 www.liveurl.com/test.php 有效,因此我必须在实际公共目录中放置第二个公共目录,以便在代码库中的任何位置将该文件引用为 /public/test.php。我真的很想在本地的同一个地方使用它并生活。我希望这是有道理的。
任何帮助或见解表示赞赏。谢谢!
您可能必须为其创建自定义代客驱动程序。
去: ~/.config/valet/Drivers
创建PhpValetDriver.php文件并粘贴此代码:
<?php
class PhpValetDriver extends ValetDriver
{
private $site_folder = '/public';
/**
* 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.'/artisan') &&
file_exists($sitePath.$this->site_folder.'/index.php')) {
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)
{
if (file_exists($staticFilePath = $sitePath.$this->site_folder.$uri)) {
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)
{
$path = $sitePath.$this->site_folder;
if ($uri == '/') {
return $path.'/index.php';
}
return strpos($uri, '.php') ? $path.$uri : $path.$uri.'.php';
}
}
Run Code Online (Sandbox Code Playgroud)
进而: valet restart
| 归档时间: |
|
| 查看次数: |
1696 次 |
| 最近记录: |