Duplicated class name between two files, now eloquent relationship is connected to wrong file

Published

I have a problem with two models, Facility and Certificate. When I created these models I just copied the code from Facility.php to Certificate.php and forgot about it.

Well when it was time to start working with the Certificate.php file I saw that it just was a copy of Facility.php so I changed it and this broke my application. I have tried clearing the cache, php artisan:optimize and nothing seems to work. Are these Eloquent relationships cached and if so is there someway I can clear/reset them?

My thought is that perhaps Eloquent has the relationship attached to the file name. Any help would be appreciated as I am stumped. Thank you.

(I am getting this in my error logs)

local.ERROR: Class ‘AppFacility’ not found {"userId":40,"exception":"[object] (Error(code: 0): Class ‘AppFacility’ not found at /var/www/html/csmmason/live/core/csm/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:745)

Facility.php

<?php

namespace App;

use IlluminateDatabaseEloquentModel;
use AppUser;

//change to Facility.php to work
class Certificate extends Model
{
    protected $fillable = [
        'score', 'exam', 'date', 'user_id'
    ];
    
    public function users()
    {
       return $this->belongsTo(User::class);
    }
}

Certificate.php

<?php

namespace App;

use IlluminateDatabaseEloquentModel;
use AppUser;

class Facility extends Model
{
    protected $fillable = [
        'name', 'system', 'department', 'seats',
    ];

    public function users()
    {
       return $this->belongsTo(User::class);
    }
}

Source: Laravel

Published
Categorised as caching, eloquent, laravel, php Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq