简体   繁体   English

Laravel 5.4方法查找

[英]Laravel 5.4 method FIND

I notice some using this code: 我注意到一些使用此代码:

$User = User::find($id);

But for me PhpStorm shows alert: 但是对我来说,PhpStorm显示出警报:

Method 'find' not found in \\App\\User 在\\ App \\ User中找不到方法'find'

If I write code like this: 如果我这样写代码:

$User = User::all()->find($id);

then no alerts.. 然后没有警报。

Can someone explain differences or why PhpStorm alerts me? 有人可以解释差异或为何PhpStorm会提醒我吗?

So looks like when installed barry laravel-ide-helper , something not installed correctly.. 因此,当安装barry laravel-ide-helper时,看起来好像安装不正确。

Fixed this problem. 解决了这个问题。

Just copy RAW text from: https://gist.github.com/barryvdh/5227822 只需从以下位置复制RAW文本: https : //gist.github.com/barryvdh/5227822

And put inside: _ide_helper.php 放在里面:_ide_helper.php

Also edited file: composer.json 还编辑了文件:composer.json

        "post-update-cmd": [
        "php artisan clear-compiled",
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan ide-helper:generate",
        "php artisan ide-helper:meta",
        "php artisan optimize"
        ]

I suppose you write the code like this 我想你写这样的代码

$User = User::query()->find($id); $ User =用户:: query()-> find($ id);

rather than use 而不是使用

$User = User::all()->find($id); $ User =用户:: all()-> find($ id);

After laravel 5.1 在laravel 5.1之后

They put the complex select function away from the Model class . 他们将复杂的select函数置于Model类之外

Official document: https://laravel.com/api/5.4/Illuminate/Database/Eloquent/Model.html 正式文件: https : //laravel.com/api/5.4/Illuminate/Database/Eloquent/Model.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM