Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheMonk's avatar

Can't find model on Production

Hi,

I've been working on a project in XAMPP on my local system and everything is running great. The code base is stable and the site works well.

I used Forge to leverage Digital Ocean and upload my site. I have the site loaded and find that when I navigate to a specific page I get an error that Laravel can't see my model from a controller. I've used the console on digital ocean and can confirm the php file for the model is in fact present. I'm guessing this might be some difference either in the php version or the Laravel version on forge.

Here's the error I'm getting:

Fatal error: Class 'App\Models\Location' not found

Here's the begining of the controller where the error comes up:

namespace App\Http\Controllers;

use DB;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Profile;
use App\Models\Location;

Any help is appreciated, thanks!

0 likes
8 replies
ohffs's avatar

Maybe check the case of the file (and class name inside) - if you're on Windows (and possibly macos, can't remember) I think it would treat 'location.php' and 'Location.php' as the same thing - but on Linux they are different.

3 likes
phpMick's avatar

Is the class name in Location.php correct?

class Location extends Model implements AuthenticatableContract,
TheMonk's avatar

I'll check tonight thanks for the comments so far!

TheMonk's avatar

Hmm here's what I reviewed:

The model file is in fact using an upper case L: "Location.php"

Here is the contents of the Location.php model:

<?php

namespace App\models;
use Illuminate\Database\Eloquent\Model;

class Location extends Model
{
    public function profiles()
    {
        return $this->hasMany('Profile');
    }
}

My controller invokes the location like so:

Location::where("address","=","")->select('id')->first();

This is written in Laravel 5.1

Any ideas?

TheMonk's avatar

A little more info. This seems to be happening on all my controllers. I have another page which references a "Profile.php" controller. And it too generates an error stating "Class 'App\Models\Profile' not found"

Here's the Profile model for it:

<?php

namespace App\models;
use Illuminate\Database\Eloquent\Model;

class Profile extends Model {
    public function locations()
    {
        return $this->hasMany('Location');
    }
}

Those are the only two custom models I'm using.

10yearsAfter's avatar
Level 13

check the namespace, I see namespace App\models and not App\Models... mayby that the problem

TheMonk's avatar

Thanks everyone, got it sorted! I had to convert the word model to lowercase. Like so:

use App\models\Profile;
use App\models\Location

Love this forum, friendly knowledgeable advice every time.

1 like

Please or to participate in this conversation.