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();

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...