问题描述
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();