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
Release: 2023-03-02 10:54:02
Original
1800 people have browsed it

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>
Copy after login
Copy after login

phpstorm error:

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

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>
Copy after login
Copy after login

phpstorm error:

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

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template