laravel 'class not found' error on production

1.6k views Asked by At

Slightly odd one here.

I have Persons and Actions. Persons can have many Actions, while each Action belongs to only one Person. I'm using Chumper's Datatables to display a list of people, including a count of their actions.

Since migrating to a production (forge) server, I'm getting

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Class 'action' not found

when calling the datatable. The error shown

/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php:721

public function hasOne($related, $foreignKey = null, $localKey = null)
{
    $foreignKey = $foreignKey ?: $this->getForeignKey();
    $instance = new $related;
    $localKey = $localKey ?: $this->getKeyName();

suggests it's a problem with my hasMany relationship:

# /models/Person.php
class Person extends Eloquent {

    public function actions()
    {
        return $this->hasMany('Action');
    }

# /models/Action.php
class Action extends Eloquent { 

    public function person()
    {
        return $this->belongsTo('Person', 'person_id');
    }

I assume these are fine, however, as it all works locally. Datatables also works fine elsewhere, calling through other items and their related actions with no trouble.

I've tried composer dump-autoload and artisan dump-autoload on the production server, to no avail. The deployment script on forge is below:

git pull origin master
composer install
php artisan migrate --env=production

I can't tell if it's a config issue, a database issue, a code issue or something else entirely. I've been back through the many similar questions but nothing's jumped out. Any help much appreciated.

2

There are 2 answers

0
taekni On BEST ANSWER

So I think I'd borked this one myself.

I'd been lazy and left function datatablePersons() in PersonsController.php using an old 'count' method, relying on long-defunct relationships (that caused n+1, so had to be binned), hence it wobbling over an actions class whenever that relationship was called upon.

Datatable functions in other controllers (with a cleaner 'count' method) work fine, so I've just rewritten datatablePersons() to use the same method.

I've not quite got the query right (in eloquent, at least) yet - see this question here: mysql join ON and AND to laravel eloquent - but the class not found error has certainly gone away.

I'm (massively) guessing that the classmap on the local machine hadn't been flushed since whatever was removed was removed, while the production machine is rebuilt every push, hence the disparity...?

Either way, it's no longer an issue.

0
michelepatrassi On

for who may have the same problem, triple check the casing of your model! I had it wrong, that's why locally on mac was working but not on the server