如何解决PHPStorm-Laravel Eloquent没有代码提示
Basically what's described in this post.
在PHPStorm中,没有雄辩方法的代码提示-这非常令人困惑(我只是在学习Eloquent)。
似乎所有提供的解决方案都不适用于Laravel 6+。当前正在使用Laravel8。想要再次推广该主题-也许有人已经找到了合适的解决方案。
代码示例:
app \ Models \ Article.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasFactory;
}
控制器:
use App\Models\Article;
$article = Article::where(...); //no code hint
几乎所有方法都适用。
解决方法
您应该使用laravel-ide-helper软件包(https://github.com/barryvdh/laravel-ide-helper)。
安装:
composer require --dev barryvdh/laravel-ide-helper
模型提示:
php artisan ide-helper:models
php artisan ide-helper:models --reset
使用--reset选项替换模型中的整个phpdoc块。
facades方法的代码提示:
php artisan ide-helper:generate
通过容器调用的类的代码提示:
php artisan ide-helper:meta
,
搜索带有where语句的内容后,必须使用get来获取数据,因此必须在末尾使用get。
$articles = Article::where(...)->get();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。