简体   繁体   中英

PhpStorm method not found in class

I'm working on a project using Laravel 5.5 and I'm using PhpStorm as IDE but it shows me

"Method 'table' not found in \\Illuminate\\Support\\Facades\\DB..."
"Referenced method is not found in subject class.. "

The code however is working perfectly but still want to know the perfect syntax.

even if you install the barryvdh/laravel-ide-helper the problem persist, there's a quick solution for this problem, if you look in the /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php class and Add this PhpDoc

/**
 * @mixin \Eloquent
 * @mixin \Illuminate\Database\Eloquent\Builder
 */

PhpStorm will now recognize all the Query building methods for all your models

Install https://github.com/barryvdh/laravel-ide-helper

composer require barryvdh/laravel-ide-helper

register it in config/app.php

use it to generate facades doc

php artisan ide-helper:generate

Your issue is already mentionned here : https://github.com/laravel/framework/issues/9162

It is an issue after 5.0.33 update.

Try directly this in your code:

\DB::table('...')->get();

To enable helpers for ide it is important to add "User::query()" if we user query() method then ide will not give such warnings it is best way to easily find eloquent feature.

Without ::query() we can't analyse that followed functions like "where, with, all, get" recognized or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM