【发布时间】:2021-10-12 16:41:25
【问题描述】:
我正在尝试制作一个示例项目来学习 laravel。我在我的计算机上设置了项目,一切正常:我有我的 web.php 将 / 路由到一个视图,但在此之前它会收集设备以便向您显示一些数据。
我决定尝试将它托管在 Debian AWS 实例上,因此我将我的仓库克隆到 /var/www/,迁移了数据库,编写了 .env、composer 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
- ...
【问题讨论】: