Eloquent ORM code prompt phpstorm

So I just started with laravel (using V5) and eloquence I'm trying to get some basic APIs and run them, and notice that many working methods don't show code tips in phpstorm

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 {
}

In one of my controllers I tried to do

User::query()->orderBy('id','desc');

User:: query() creates an eloquent builder object. Orderby() behaves correctly without errors However, when you type user:: query() – >, phpstorm does not display orderby() (or take(), skip(), I'm sure others) and warns you when you actually use it

I am using the laravel ide helper, which is very helpful to provide code tips to the facade, but not the view of the model / builder

Has anyone solved this problem?

Solution

For future Google employees, if you still insist on using laravel, Op may also be Op

The laravel ide helper package gracefully solves this problem. I believe it is a relatively new function; Generate model phpdocs

You can use this command to generate separate files for all phpdocs:

PHP artisan ide-helper:models

The generated metadata will look 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 me problems in PHP storm, but the software complained in multiple class definitions Fortunately, one option can be written directly to the model file:

PHP artisan ide-helper:models -W

There are several options and settings available if you need to adjust the behavior, but that's the point

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>