Laravel:BadMethodCallException方法[查找]不存在 [英] Laravel : BadMethodCallException Method [find] does not exist
问题描述
当尝试使用模型对象User从数据库中提取一些值时,出现以下错误:BadMethodCallException Method [find] does not exist
when trying to extract some values from the database using the model object User I get the following error : BadMethodCallException Method [find] does not exist
这是我的文件: 模型用户
Here are my files : Model User
<?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;
}
}
控制器用户:
<?php
class user extends BaseController {
public function showWelcome($id)
{
$user1 = User::find($id);
return View::make('users.index', array('user' => $user1)); //
}
}
查看用户/index.php
View users/index.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>first page</title>
</head>
<body>
<?php echo 'Hello'; ?>
</body>
</html>
和routes.php:
and the routes.php :
<?php
Route::get('user/{id}', 'user@showWelcome');
Route::get('/', function()
{
return View::make('hello');
});
感谢您的帮助
推荐答案
您不应收到此错误,因为似乎您使用的是Eloquent,并且上面有一个find()
方法.
You should not get this error, because it seems like you are using Eloquent and there is a find()
method on it.
但是您收到此错误,并且有一些可能的原因:
But you are getting this error and there are some possible reasons:
1)您要调用的User::
与此处显示的不同,以检查控制器中的执行情况:
1) The User::
you are calling is not the same you are showing here, to check execute in your controller:
$reflector = new ReflectionClass("User");
$fn = $reflector->getFileName();
dd($fn);
它必须向您显示课程的完整路径.
It must show you the full path of your class.
2)自动加载有问题,您可以运行:
2) There's is something wrong with autoloading, you can run:
composer dumpautoload
尝试修复它.
3)Laravel源出了点问题,您可以删除Laravel代码:
3) There is something wrong with Laravel sources, you can delete Laravel code:
rm -rf vendor/laravel
然后重新安装
composer update
这篇关于Laravel:BadMethodCallException方法[查找]不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!