phpstrom用模型where查询,字段为什么不会提示?

如下图:laravel 用select查询数据库字段不会进行提示,注释是通过
barryvdh/laravel-ide-helper 生成


yii2 的model 查询会出现提示, 注释手写

请问laravel 如何实现和yii2 的model 字段提示????

本作品采用《CC 协议》,转载必须注明作者和本文链接
勿以恶小而为之,勿以善小而不为
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 15
颠倒的玉石

ide-helper:models这个能达到你想要的一半效果

4年前 评论
看看看世界 (楼主) 4年前
颠倒的玉石 (作者) 4年前
Epona
User::query()->where(xxxxx)
4年前 评论
看看看世界 (楼主) 4年前

User::query()->where() 配置phpstorm database 就可以提示

4年前 评论
看看看世界 (楼主) 4年前
wow_Garlic 4年前
看看看世界 (楼主) 4年前
wow_Garlic 4年前
liunian-zy 4年前
vilson 4年前
liunian-zy 4年前

我安装你的设置了数据库,但是还是没提示

4年前 评论
看看看世界 (楼主) 4年前
vilson 4年前
wozaihanni 4年前
看看看世界 (楼主) 4年前
看看看世界 (楼主) 4年前
看看看世界 (楼主) 4年前
vilson 4年前
铁牛 (作者) 4年前

:joy:还有提示啊居然,我一直都是自己敲的,学到了学到了

4年前 评论
看看看世界 (楼主) 4年前
liunian-zy (作者) 4年前

学到了

4年前 评论

感觉它的这个提示,好像对database里设置的前缀支持得不是很好。

4年前 评论
liunian-zy 4年前
mowangjuanzi

我自己封装了一个 trait 文件。然后每个Model 都调用了它,就可以了。

trait 文件内容如下:

<?php


namespace App\Models;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Trait ModelExtendTrait
 * @package App\Models
 * @method static static firstOrCreate(array $attributes, array $values = [])
 * @method static static|null find(string $id, array $columns = ['*'])
 * @method static Collection|static[] findMany(Arrayable|array $ids, array $columns = ['*'])
 * @method static bool chunkById(int $count, callable $callback, string|null $column = null, string|null $alias = null)
 * @method static static first(... $columns = ['*'])
 * @method static Builder forPage(int $page, int $perPage = 15)
 * @method static Builder from($table, $as = null)
 * @method static Collection get($columns = ['*'])
 * @method static Builder groupBy(array|string ...$groups)
 * @method static Collection hydrate(array $items)
 * @method static Builder limit(int $value)
 * @method static int increment($column, $amount = 1, array $extra = [])
 * @method static bool insert(array $values)
 * @method static int insertGetId(array $values, $sequence = null)
 * @method static Builder join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
 * @method static Builder leftJoin($table, $first, $operator = null, $second = null)
 * @method static Builder orderBy($column, $direction = 'asc')
 * @method static Builder orderByDesc($column)
 * @method static LengthAwarePaginator paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Support\Collection pluck($column, $key = null)
 * @method static Builder select(...$columns)
 * @method static Builder when($value, $callback, $default = null)
 * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static Builder whereBetween($column, array $values, $boolean = 'and', $not = false)
 * @method static Builder whereNotIn($column, $values, $boolean = 'and')
 * @method static Builder whereIn($column, $values, $boolean = 'and', $not = false)
 *
 * @see Builder
 */
trait ModelExtendTrait
{

}

然后创建的Model就是这样的:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Horn extends Model
{
    use ModelExtendTrait;
}

这样就可以实现写的时候有提示了。

如果用的方法没有,可以自己再去加

4年前 评论
看看看世界 (楼主) 4年前
mowangjuanzi (作者) 4年前

tabnine phpstorm插件 你值得拥有

4年前 评论
随波逐流

php artisan ide-help:model App\\Models\\User -W -R

4年前 评论

大佬多库好使吗

4年前 评论
看看看世界 (楼主) 4年前

作者做一波更新吧

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!