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

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


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

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

本作品采用《CC 协议》,转载必须注明作者和本文链接
勿以恶小而为之,勿以善小而不为
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 15
颠倒的玉石

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

2年前 评论
钟海彬 (楼主) 2年前
颠倒的玉石 (作者) 2年前
Epona
User::query()->where(xxxxx)
2年前 评论
钟海彬 (楼主) 2年前

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

2年前 评论
钟海彬 (楼主) 2年前
wow_Garlic 2年前
钟海彬 (楼主) 2年前
wow_Garlic 2年前
liunian-zy 2年前
vilson 2年前
liunian-zy 2年前

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

2年前 评论
钟海彬 (楼主) 2年前
vilson 2年前
wozaihanni 2年前
钟海彬 (楼主) 2年前
钟海彬 (楼主) 2年前
钟海彬 (楼主) 2年前
vilson 2年前
铁牛 (作者) 2年前

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

2年前 评论
钟海彬 (楼主) 2年前
liunian-zy (作者) 2年前

学到了

2年前 评论

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

2年前 评论
liunian-zy 2年前

我自己封装了一个 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;
}

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

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

2年前 评论
钟海彬 (楼主) 2年前
mowangjuanzi (作者) 2年前

tabnine phpstorm插件 你值得拥有

2年前 评论
随波逐流

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

2年前 评论

大佬多库好使吗

2年前 评论
钟海彬 (楼主) 2年前

作者做一波更新吧

2年前 评论

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