i’m trying to make an example project to learn laravel. I set up the project on my computer and everything worked fine: I have my web.php
that routes /
to a view, but before that it collects devices so it can show you some data.
I decided to try and host it on a Debian AWS instance so I cloned my repo in /var/www/
, migrated the database, wrote the .env
, composer install
, set folder ownership to admin user and permissions to storage and bootstrap.
Once i configured nginx i tried it by navigating to the url and the answer was Class "AppModelsDevice" not found.
I checked the namespaces, file names, I even read that debian is a sucker for caps sensitivity so i double checked every capital letter in every name and since app folder is named app and not App i even tried to import it as appModelsDevice
but to no avail.
I also tried with composer dump-autoload
as many on SO suggested, but nothing changed at all.
Am i missing something?
Device.php
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
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 appModelsDevice; //appModelsDevice - AppModelsDevice - AppModelDevice
use IlluminateSupportFacadesRoute;
/*
|--------------------------------------------------------------------------
| 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]);
});
Structure:
- app
- - Models
- - - Device
- - ...
- ...
- routes
- - web.php
- ...
2
Answers
I think i'm going nuts, i just tried again with
AppModelsDevice
and got the error, re-changed it toappModelsDevice
and got the error again and finally re-re-changed it toAppModelsDevice
and now it works...... have no idea why or how...Try to import it like so
use AppModelsDevice;
instead ofuse appModelsDevice;
See this link also