Laravel作曲家更新模型方法调用后未定义 [英] Laravel after composer update model method call undefined
问题描述
我正在使用Laravel 4.2开发一个项目,我创建了一些模型和控制器,并从控制器中调用了模型函数,问题是在composer update
命令后它显示此错误:Call to undefined method Department::getAllParent()
,但在composer update
之前它能正常工作.您认为此问题出了什么问题?预先感谢
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
型号代码:
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;
}
}
和控制器代码:
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);
}
}
推荐答案
不要认为这与您的问题有关,但这可能是处理这些查询的更好方法.您正在使用Eloquent并设置table参数.为什么不使用Eloquent的内置功能?
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();
}
}
我认为您也许也可以使用$this->get();
,但是我现在无法测试.
I think you might also be able to use $this->get();
but I can't test right now.
这篇关于Laravel作曲家更新模型方法调用后未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!