【问题标题】:Laravel: Class "App\Models\Device" not found in web.php (only in production)Laravel:在 web.php 中找不到类“App\Models\Device”(仅在生产中)
【发布时间】:2021-10-12 16:41:25
【问题描述】:

我正在尝试制作一个示例项目来学习 laravel。我在我的计算机上设置了项目,一切正常:我有我的 web.php/ 路由到一个视图,但在此之前它会收集设备以便向您显示一些数据。

我决定尝试将它托管在 Debian AWS 实例上,因此我将我的仓库克隆到 /var/www/,迁移了数据库,编写了 .envcomposer install,将文件夹所有权设置为管理员用户,并将权限设置为存储和引导程序。

一旦我配置了 nginx,我通过导航到 url 进行了尝试,答案是 Class "App\Models\Device" not found.

我检查了命名空间、文件名,我什至读到 debian 对大写敏感度很差,所以我仔细检查了每个名称中的每个大写字母,因为 app 文件夹被命名为 app 而不是 App,我什至尝试将其导入为 @ 987654327@但无济于事。

我也尝试了composer dump-autoload 在 SO 上的许多建议,但没有任何改变。

我错过了什么吗?

设备.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Device extends Model
{
    use HasFactory;
    use SoftDeletes;


    protected $fillable = [
        'serial',
        'livello_acqua',
        'umidita',
        'temperatura',
        'livello_mangime',
        'stato_rele_1',
        'stato_rele_2',
        'stato_rele_3',
        'stato_rele_4',
        'descrizione',
    ];

    public static function findBySerial($serial){
        return Device::where('serial', $serial)->get();
    }

    public static function findByUser($id){
        return Device::where('user_id', $id)->get();
    }

}

web.php

<?php

use app\Models\Device; //\app\Models\Device - App\Models\Device - \App\Model\Device
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    $devices = Device::all();

    return view('index')->with(['devices' => $devices]);
});

结构:

- app
- - Models
- - - Device
- - ...
- ...
- routes
- - web.php
- ...

【问题讨论】:

    标签: php laravel debian


    【解决方案1】:

    我想我快疯了,我只是用App\Models\Device 再次尝试并得到错误,将其重新更改为app\Models\Device 并再次出现错误,最后重新将其重新更改为App\Models\Device 和现在它起作用了......不知道为什么或如何......

    【讨论】:

      【解决方案2】:

      尝试像use App\Models\Device;而不是use app\Models\Device;那样导入它

      看到这个link also

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-07
        • 2021-10-15
        • 1970-01-01
        • 2022-08-11
        • 2021-12-28
        • 2017-06-07
        • 2017-10-04
        • 1970-01-01
        相关资源
        最近更新 更多