Php Laravel:BadMethodCallException方法[find]不存在
当尝试使用模型对象用户从数据库中提取某些值时,我遇到以下错误:Php Laravel:BadMethodCallException方法[find]不存在,php,laravel,laravel-4,Php,Laravel,Laravel 4,当尝试使用模型对象用户从数据库中提取某些值时,我遇到以下错误:BadMethodCallException方法[find]不存在 这是我的档案: 模型用户 <?php use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class User extends Eloquent implements UserInterface, RemindableInterface {
BadMethodCallException方法[find]不存在
这是我的档案:
模型用户
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
public function projects()
{
return $this->belongsToMany('Project');
}
public function trys()
{
return $this->hasMany('Try');
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
您不应该出现此错误,因为您似乎在使用Eloquent,而且上面有一个find()
方法
但您会遇到此错误,可能有一些原因:
1) 您要调用的用户::
与此处显示的不同,以检查控制器中的执行:
$reflector = new ReflectionClass("User");
$fn = $reflector->getFileName();
dd($fn);
它必须向您显示类的完整路径
2) 自动加载有问题,您可以运行:
composer dumpautoload
试图修复它
3) Laravel源有问题,您可以删除Laravel代码:
rm -rf vendor/laravel
然后重新安装
composer update
有时,当Laravel中存在同名的另一个模型并且很可能优先于您的模型时,会导致此冲突。避免使用“关键词”。对我来说,我的问题是调用我的模型:表单和我的db表(来自迁移):表单
在myFormController中运行以下命令:
$reflector = new ReflectionClass("Form");
$fn = $reflector->getFileName();
dd($fn);
向我展示了“真实的”表单位于框架中:
"/home/pkanane/laravel_appz/cpay/vendor/laravel/framework/src/Illuminate/Support/Facades/Form.php"
因此,我刚刚将我的模型名更改为WebForm,将我的db表更改为web\u forms,它不是已经在雄辩的父类中实现了吗?您的一个服务提供者(可能是ViewServiceProvider)中调用了find()方法。我尝试了3个选项,但都不起作用,使用选项1,我得到了:Class\ConsultorioDigital\Models\VocalUser\Model不存在抱歉,这是我的类名,我在这里用它做了一个测试,但忘记了编辑。当然,将其更改为User
。它向我显示了一个错误的文件名:string(48)“/mylaravelapp/app/controllers/User.php”模型类User.php和控制器类User.php之间似乎存在冲突,我通过将控制器类名更改为UserController解决了这一问题。谢谢CarlosI我使用了一个名为Form的模型和一个名为forms的表,遇到了完全相同的问题,我现在正在更改我的模型和表名。疯狂
composer update
$reflector = new ReflectionClass("Form");
$fn = $reflector->getFileName();
dd($fn);
"/home/pkanane/laravel_appz/cpay/vendor/laravel/framework/src/Illuminate/Support/Facades/Form.php"