目标类 [App\Http\Controllers\welcome] 不存在。Laravel 6 中的错误

Upa*_*han 2 laravel

我在 laravel 6 中收到 Target class [App\Http\Controllers\welcome] does not exist 错误。一切似乎都很好。

在路由/ web.php

Route::get('/','welcome@index');
Run Code Online (Sandbox Code Playgroud)

Welcome.php 文件在本地主机上一切正常,但是当我上传到服务器时出现该错误。

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Constant_model;



class Welcome extends Controller
{
public function index(){

      $snippets = Constant_model::getDataAllWithLimit('snippets',"id",'DESC',10);

      $data = array(
        'title'=>'Mytitle',
        'description'=>'Hello',
        'seo_keywords'=>'',
        'snippets'=>$snippets

        );

       return view('welcome',$data);    
 }
 }
Run Code Online (Sandbox Code Playgroud)

Lob*_*Baz 5

由于您的控制器类命名为Welcome,您的路由参数应拼写相同,包括大写:

Route::get('/','welcome@index');
Run Code Online (Sandbox Code Playgroud)

应该:

Route::get('/','Welcome@index');
Run Code Online (Sandbox Code Playgroud)

传统上,类 Unix 操作系统对文件区分大小写,而 Microsoft Windows 不区分大小写。

这就是它在您的本地环境(您可能有一台 Windows 机器)上运行但在您的服务器上失败(可能运行 Linux)的原因。