【问题标题】:Laravel view working in production but not locallyLaravel 视图在生产中工作但不在本地
【发布时间】:2021-06-08 06:00:15
【问题描述】:

当我使用 XAMPP 转到本地计算机上的特定 url 时

在生产服务器中

本地请求没有可用的响应数据


还有其他页面使用与此相同的页眉和页脚,并且它们在本地和生产服务器中都可以正常加载。

这是编辑的样子

/**
 * Show the form for editing the specified resource.
 *
 * @param  \App\OrganizationUser  $org_user
 * @return \Illuminate\Http\Response
 */
public function edit(Request $request, OrganizationUser $org_user, Organization $model1, User $model2)
{
    // Check if user is admin
    $auth_user = Auth::user();

    $path = $request->path();

    $organization_id = (int)explode('/', $path)[1];

    $user_id = (int)explode('/', $path)[3];

    //dd($org_user->load('user')->load('organization'));

    if($auth_user->isAdmin()) {

        return view('organizations.users.edit', [
                                                'org_user' => $org_user->load('user')->load('organization')->where('id', $user_id)->first(),
                                                'organizations' => $model1::where('id', $organization_id)->get(['id', 'name']),
                                                'users' => $model2->get(['id', 'name'])
                                                ]);        
    
    } else {


        abort(404);

    }
    
}

到目前为止我尝试了什么

  1. 清除配置缓存
php artisan config:clear
  1. 清除路由缓存
php artisan route:clear
  1. 清除视图缓存
php artisan view:clear
  1. 清除事件缓存
php artisan event:clear
  1. 清除应用缓存
php artisan cache:clear
  1. 清除所有缓存
php artisan optimize:clear
  1. 从 Composer 的缓存中清除内容
composer dump-autoload
  1. 清除 NPM 缓存
npm cache clean --force
  1. 使用不同的浏览器(在 Chrome 和 Firefox 中测试)。

  2. 通过 XAMPP 控制台重启 Apache。

  3. 重启电脑。


编辑

根据要求,这是 /public 文件夹中的 .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

【问题讨论】:

  • 如果您还没有在.env 中启用调试。看看你项目的底部laravel.log,那里可能有一些错误细节。
  • 您的本地服务器似乎无法提供文件
  • AllowOverride none替换成AllowOverride AlleveryWhere并重启apache
  • @mohammadasghari 刚刚对此进行了测试,并将 httpd.conf 和 httpd-xampp.conf 中的 AllowOverride none 更改为 AllowOverride All。另外,Require all deniedRequire all granted
  • 您的storage/logs/laravel.log 中也没有任何内容?

标签: php laravel apache xampp windows-10


【解决方案1】:

我设法使它工作的方法是禁用 XAMPP 的 Apache 并改为运行

php artisan serve

现在我可以正常使用了。

【讨论】:

    【解决方案2】:

    试试这个,改变你的 httacces 文件:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} !^public
        RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    

    【讨论】:

    • 不管怎样,你解决了你的问题,这就够了;)
    • 有点...这实际上是一种解决方法,因为在 Apache 始终在后台运行之前,我不需要继续执行 php artisan serve... 现在感觉更像是在与ng serve 成角度:P
    猜你喜欢
    • 2021-12-28
    • 1970-01-01
    • 2021-10-12
    • 2021-09-21
    • 2017-07-15
    • 1970-01-01
    • 2021-12-05
    • 2023-03-19
    • 2016-07-16
    相关资源
    最近更新 更多