Laravel after composer update model method call undefined

泪湿孤枕 提交于 2019-12-12 04:25:50

问题


I am working on a project with Laravel 4.2 and I created some models and controllers and called model function from controller, the problem is after composer update command it displays this error: Call to undefined method Department::getAllParent() but before composer update it works fine. You think what is the problem with this issue? thanks in advance

Model code:

class Department extends Eloquent{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'department';

    public static function getAll()
    {

        $table = DB::table('department');
        $object = $table->get();

        return $object;
    }
    public static function getAllParent()
    {

        $table = DB::table('department');
        $table->where('parent',0);
        $object = $table->get();

        return $object;
    }
}

And Controller code:

class DepartmentController extends BaseController
{

    /*
    Getting all records from department
    @param: none
    @Accessiblity: public
    @return: Object
    */
    public function getAllDepartment()
    {
        //get data from model
        $deps = Department::getAllParent();
        $depAll = Department::getAll();

        //load view for users list
        return View::make("department.dep_list")->with('deps',$deps)->with('all',$depAll);
    }
}

回答1:


Don't think this is related to your issues but this might be a better way to handle these queries. you are using Eloquent and setting the table parameter. why not use Eloquent's build in power?

class Department extends Eloquent{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'department';

    public static function getAll()
    {
        return Department::get();
    }
    public static function getAllParent()
    {
        return Department::where('parent', 0)->get();
    }
}

I think you might also be able to use $this->get(); but I can't test right now.



来源:https://stackoverflow.com/questions/28859001/laravel-after-composer-update-model-method-call-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!