Home >Backend Development >PHP Tutorial >lumen 5.3 EloquentModel class does not have find, findOrFail, where, first and other methods

lumen 5.3 EloquentModel class does not have find, findOrFail, where, first and other methods

WBOY
WBOYOriginal
2016-12-01 01:27:271828browse

User inherits from the EloquentModel class. Under the lumen5.3 framework, the code below is in the phpstorm framework

<code>public function view($id){
        User::all();
        User::find($id);
        return  User::findOrFail($id);
}
</code>

phpstorm error:

<code>Method 'find' not found in \App\User
Method 'findOrFail' not found in \App\User。</code>

all method is fine.

I changed the framework to lumen 5.0.3 and this error will not be reported.
Has the framework method been changed? How to write it in lumen5.3?

Reply content:

User inherits from the EloquentModel class. Under the lumen5.3 framework, the code below is in the phpstorm framework

<code>public function view($id){
        User::all();
        User::find($id);
        return  User::findOrFail($id);
}
</code>

phpstorm error:

<code>Method 'find' not found in \App\User
Method 'findOrFail' not found in \App\User。</code>

all method is fine.

I changed the framework to lumen 5.0.3 and this error will not be reported.
Has the framework method been changed? How to write it in lumen5.3?

Have you read this article? It seems that if you want to use Eloquent, you need to enable it separately

If you want to use Eloquent ORM, you should uncomment the $app->withEloquent() call in the bootstrap/app.php file.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn