Laravel : BadMethodCallException Method [find] does not exist

假如想象 提交于 2019-12-05 09:51:49

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) 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) There's is something wrong with autoloading, you can run:

composer dumpautoload

To try to fix it.

3) There is something wrong with Laravel sources, you can delete Laravel code:

rm -rf vendor/laravel

and install it again

composer update

Sometimes this conflict is caused when another model of the same name exists in Laravel and most likely has a precedence over your model. Avoid "Key Words". For me, my problem was calling my model: Form and my db table (from a migration): forms.

Running the following cmd in my FormController:

$reflector = new ReflectionClass("Form");
$fn = $reflector->getFileName();
dd($fn);

showed me that the "real" Form was located in the Illuminate framework:

"/home/pkanane/laravel_appz/cpay/vendor/laravel/framework/src/Illuminate/Support/Facades/Form.php" 

So I just changed my model name to WebForm and my db table to web_forms

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