[英]Call to undefined method
I want to create a custom function inside my model in order to retrieve data with more compicated queries but I get an error that my method is undefined. 我想在模型中创建一个自定义函数,以便通过更复杂的查询检索数据,但是出现一个错误,提示我的方法未定义。
//Model
class Host extends Eloquent {
//custom function
//or public static function
public function allWithUser() {
}
}
//Controller
//or Host::allWithUser();
$hosts = with(new Host)->allWithUser();
You have some options to access this method, but I think those you shown to us are not right. 您可以使用某些方法来访问此方法,但我认为您向我们展示的方法不正确。 Those (non static) ways you might be successful:
您可能会成功的那些(非静态)方法:
$hosts = (new Host)->allWithUser();
and 和
$hosts = new Host;
$hosts->allWithUser();
But your static version should have worked. 但是您的静态版本应该可以使用。
EDIT 编辑
If it does not work, you must be instantiating a different version of the Host class. 如果不起作用,则必须实例化Host类的其他版本。
Change the model class name from ´Host´ to ´HostTest´ and check if 将模型类名称从“ Host”更改为“ HostTest”,然后检查是否
$hosts = new Host;
Still works for you. 仍然为您工作。
EDIT 2 编辑2
If you find you have two classes using the same name, you can check the file 如果发现有两个使用相同名称的类,则可以检查文件
vendor/composer/autoload_classmap.php
All your autoloaded classes should be listed there. 您所有自动加载的类都应在此处列出。
And if you are on a Linux, you can 如果您使用的是Linux,则可以
find /your/app/path | grep Host.php
and 和
sudo grep -r "class Host" /your/app/path/*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.