问题描述
所以我刚刚开始与Laravel(使用v5)和雄辩。我正在努力获取一些基本的API并运行,并注意到许多工作方法不显示在PhpStorm的代码提示所以我有这个模型:
命名空间Project\Models;
使用Illuminate\Database\Eloquent\Model;
使用Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
使用Illuminate\Contracts\Auth\CanResetPassword作为CanResetPasswordContract;
class用户扩展模型
实现AuthenticatableContract,CanResetPasswordContract {
}
在我的一个控制器中,我尝试执行
User :: query() - > orderBy 'id','desc');
User :: query()
创建一个雄辩的构建器
对象和 orderBy()
正确运行,没有错误。但是,PhpStorm不显示 orderBy()
(或 take()
, skip()当我输入
User :: query() - >
,并在实际使用时发出警告,我确定其他人)。
我正在使用已经帮助的非常感谢向门面提供代码提示,而不是向模型/构建者显示出来。
有没有人有解决这个问题?
对于未来的Google员工,如果您仍然坚持使用Laravel,OP也可能是OP。
软件包非常优雅地解决了这个问题,我相信这是一个相对较新的功能;生成模型PHPDocs。
您可以使用以下命令为所有PHPDocs生成单独的文件:
php artisan ide-helper:models
生成的元数据将如下所示对于每个类:
命名空间应用{
/ **
* App \Post
*
* @property integer $ id
* @property integer $ author_id
* @property string $ title
* @property string $ text
* @property \\ \\Carbon\Carbon $ created_at
* @property \Carbon\Carbon $ updated_at
* @ property-read \User $ author
* @ property-read \Illuminate\数据库\Eloquent\Collection | \Comment [] $ comments
* /
class Post {}
}
这导致了我在PHPStorm中的问题,但是软件对于多个类定义抱怨。幸运的是,一个选项可以直接写入模型文件:
php artisan ide-helper:models -W
如果需要调整行为,还有几个可用的选项和设置,但这是它的要点。
So I'm just starting off with Laravel (using v5) and Eloquent. I'm working on getting some basic APIs up and running and noticing that a lot of working methods don't show up in PhpStorm's code hinting
So I have this model:
namespace Project\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model
implements AuthenticatableContract, CanResetPasswordContract {
}
And in one of my controllers I try to do
User::query()->orderBy('id', 'desc');
User::query()
creates a Eloquent Builder
object and orderBy()
behave properly and without error. However, PhpStorm does not show orderBy()
(or take()
, skip()
, and I'm sure others) when I type User::query()->
and gives warnings when I actually do use it.
I am using Laravel IDE Helper which has helped immensely with bringing code hints to the Facades, but not to the models/builders it would seem.
Does anyone have a solution to this?
For future Googlers, and perhaps OP as well if you are still sticking to Laravel.
The laravel-ide-helper package solves this issue for you quite elegantly, with what I believe is a relatively new feature; generated model PHPDocs.
You can generate a separate file for all PHPDocs with this command:
php artisan ide-helper:models
The generated metadata will look something like this for each class:
namespace App {
/**
* App\Post
*
* @property integer $id
* @property integer $author_id
* @property string $title
* @property string $text
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property-read \User $author
* @property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments
*/
class Post {}
}
This caused issues for me in PHPStorm however, where the software was complaining about multiple class definitions. Luckily an option is readily available for writing directly to the model files:
php artisan ide-helper:models -W
There are a few more options and settings available if you need to tweak the behavior, but this is the gist of it.
这篇关于雄辩的ORM代码提示PhpStorm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!