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

lolotoobo's avatar

L5.5 Model can't be founded in distant server but works on local server.

Hi

I have a model called option in App\Lolotoobo\Models and I call it in the controller's constructor as

$this->options = \App\lolotoobo\Models\Option::getAutoloaded();

It works perfectly on local server, but on a Digital Ocean server I have

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'App\lolotoobo\Models\Option' not found

Thanx for your help

0 likes
9 replies
shez1983's avatar

have you composer dumpautoload, and various commands available? (optimize, cleared cache (opcache if available) etc etc..

does it happen with JUST this model or ANY model?

lolotoobo's avatar

It seems it's only this class...

Here is the class.

<?php

namespace App\Lolotoobo\Models;

class Option extends Model
{

    public $timestamps = false;

    protected $fillable = [
        'autoload',
        'page',
        'name',
        'value',
        'validation',
    ];

    public static function get($name, $default=null)
    {
        $option = Option::where('name', $name)->first();
        if (empty($option)) {
            return $default;
        }

        return $option;
    }

    public static function set($name, $value, $autoload = true, $validation = '')
    {
        $option = Option::where('name', $name)->first();

        if (empty($option)) {
            $option = new Option();
            $option->name = $name;
        }

        $option->value      = $value;
        $option->autoload   = $autoload;
        $option->validation = $validation;

        $option->save();
    }

    // private static function translateToArray($source)
    // {
    //     $arr = [];
    //     foreach($source as $val) {
    //         $arr[$val['name']] = [
    //             'page'=>$val['page'],
    //             'value'=>$val['value'],
    //             'autoload'=>$val['autoload'],
    //             'validation'=>$val['validation'],
    //         ];
    //     }

    //     return $arr;
    // }

    /**
     * Generate an array of objects
     *
     * @param  mixed $source Datas
     * @return mixed         Array of arrays
     */
    private static function translateToArray($source)
    {
        $returnArray = [];

        foreach($source as $val) {
            $newObj = new \stdClass;
            $newObj->page = $val['page'];
            $newObj->value = $val['value'];
            $newObj->autoload = $val['autoload'];
            $newObj->validation = $val['validation'];

            $returnArray[$val['name']] = $newObj;
        }

        return $returnArray;
    }

    public static function getAutoloaded()
    {
        return self::translateToArray(Option::where('autoload', true)->get());
    }

    public static function getByPage($page)
    {
        return self::translateToArray(Option::where('page', $page)->get()->toArray());
    }

}
jlrdw's avatar

Remember linux is case sensitive.

lolotoobo's avatar

I'm coding with PHPStorm then I should have no problem with case

jlrdw's avatar
$option = new Option();

Is probably causing problems, refactor your code.

shez1983's avatar
shez1983
Best Answer
Level 23

$option = new Option()..

why would this be causing problem?

I also dont see the relevance of

I'm coding with PHPStorm then I should have no problem with case

having seen the model.. i am not sure because you are creating get() func in the model.. and eloquent already has get() func.. so there is some error in the code/file which is stopping the class from being parsed...

lolotoobo's avatar

Yes $option = new Optionis not the problem.

I renamed get()by getOne()and set()by setOne() and instead of calling \App\lolotoobo\Models\OptionI call Optionand I declare a use App\lolotoobo\Models\Option

Now it works :)

Tkank you guys

shez1983's avatar

i am surprised phpstorm didnt complain.. it should have.. not that you were overwriting it but that the params dont match the overloaded func

lolotoobo's avatar

Yes I'm really surprised too :( I thought it was the base of an IDE....

Please or to participate in this conversation.