如何移动 Laravel 11 公共文件夹?

问题描述 投票:0回答:1

我尝试搜索教程来移动公用文件夹,但从所有指南来看,代码似乎与版本11不同。我想要移动的文件夹结构如下:

  • public(公共文件夹在这里)
  • 程序(要存储在该文件夹中的所有其他文件)

我已将 public/index.php 文件修改为:

<?php

use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../program/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require __DIR__.'/../program/vendor/autoload.php';

// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../program/bootstrap/app.php')
    ->handleRequest(Request::capture());

但是,当我尝试运行

php artisan serve
时,我收到错误

   Symfony\Component\Process\Exception\RuntimeException

  The provided cwd "C:\wamp64\www\my-project\program\public" does not exist.

需要修改哪些内容才能使其正常工作?

php laravel laravel-11
1个回答
0
投票

您必须注意如何加载项目。 Laravel 有自己的路径处理函数。 如果您想将

public Path
函数使用的
public_path()
更改为默认应用程序入口。您应该在
App\Providers\AppServiceProvider.php
类中注册一个新路径。

// edit the register method
public function register()
{
    $this->app->bind('path.public', function() {
        return base_path() . '/program/public';
    });
}

之后,你的apache入口文件将是

C:\wamp64\www\my-project\program\public\index.php

© www.soinside.com 2019 - 2024. All rights reserved.