9

This is a repeat question - eg: Laravel 4 migrations - class not found

However, I've tried every solution (from every forum I could find) and cannot figure this out.

Scenario

I created a Laravel 4 project on my local machine - added some classes, controllers, views, etc - the project works great.

I then copy this fresh repo onto my DO server - install dependencies with composer, etc. The project looks good, except for one page that shouts an error:

Class 'company' not found
Symfony\Component\Debug\Exception\FatalErrorException
…/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php593

You can view this page here.

I've tried...

I've updated composer. I've tried "dump-autoload". I changed the 'minimum-stability' to 'stable' in the composer.json file (yes, this was a proposed solution on a forum post).

Other solutions have to do with adding "psr-4" or "psr-0" into the composer.json file depending on the composer version - tried both.

What boggles my mind about this the most, is that this page works great on my local machine, but not on the DO server....If you guys need more info about something to fish this answer out, just let me know.

Any help is appreciated :)


this is what my composer.json file looks like:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.0.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}
Community
  • 1
  • 1
geoctrl
  • 685
  • 7
  • 22
  • 3
    i feel like it's a case sensitivity issue here. you can see under `vendor/composer/autoload_classmap.php` if and how your class **company** gets loaded, since it works under your dev environment. – Simon Wicki Apr 03 '14 at 06:58
  • Can you add the code of page which is showing the error? If other things are working fine then I think there is no issue with composer.json. – akshaykumar6 Apr 03 '14 at 07:02

7 Answers7

36

Most probably (I'm pretty sure) your local environment is Windows and live server is Linux. So if the class company class file is used as company.php on local server then it's same Company.php on local server but as Linux follows case sensitive rules so it reads the company.php and Company.php as two different files.

So, if you have file name used Company.php then make sure you are refering the class using same case as Company not company (lower), in windows c and C doesn't matter but on Linux/Unix it does because of it's case sensitive nature.

Sark
  • 299
  • 2
  • 21
The Alpha
  • 143,660
  • 29
  • 287
  • 307
  • 2
    indeed! I'm not sure why only one class didn't work (they all were set up the same way...), but changing the class names to lowercase and auto-dumping it again fixed it up. Thanks again – geoctrl Apr 03 '14 at 15:00
  • 2
    Perfect!!! In may case, my localhost is Mac, and even different it works. In my server I am using Apache with NGINX, then if it is different (uppercase and lowercase) it doesn't work. I have been wasted a lot time with that, but you were right. Thks. – LuizEduardoMPF Dec 03 '19 at 11:39
7

I have faced the same problem when I added/created a new model class called Follower_Group in a project I worked on, and after some search I came to a solution that worked pretty well in my case. Try this:

  1. Execute the command composer dump-autoload in your local machine's terminal.
  2. Re-upload these 2 folders /bootstrap and /vendor/composer from your local machine to your server.
Amr
  • 4,809
  • 6
  • 46
  • 60
1

In case you are using git, and you want Git to be case sensitive, adjust its configs:

Just use the following command for the current repository:

git config core.ignorecase false

For global setting:

git config --global core.ignorecase false

Mohamed Mo Kawsara
  • 4,400
  • 2
  • 27
  • 43
1

I had the same problem.

It was a path called app/helpers and inside it, my class Log:

namespace App\Helpers;

class Log {
 ...
}

On my local machine, it was working fine, but on the Server, I've got an exception.

The solution? Change the path name from "helpers" to "Helpers".

So, pay attention to the uppercase ;)

-1

During the upload sometimes it happens like the files get uploaded but the content inside it is blank.

I faced similar issue and fixed it re-uploading the file.

When I see the file on the server, it is of 0 bytes so i have to re upload the local file to fix the issue.

Jnanaranjan
  • 1,304
  • 15
  • 31
-1

Run command composer dump-autoload in your local machine terminal, and then Re-upload composer folder from vendor in local machine to your server.

Blue
  • 22,608
  • 7
  • 62
  • 92
-2

THIS WORKS FOR ME -> on your live server execute: composer install This should install all the necessary packages that are missing.

Hope this help someone!

Roga Men
  • 512
  • 6
  • 16