5

Im f*cking crazy whith PhpStorm when tried to fix a popular error Method 'Bla bla' not found in class.

I have been searching for days in google whith hope to find out the way for this problem but no luck.

Almost every singel topic I have read are pointing me to this laravel-ide-helper but after Install thousand times (with fresh laravel project), PhpStorm still not recognize those damn method.

I also install laravel plugin in PhpStorm but still not work too, what can I do now?

Here is my code.

<?php

namespace App\Http\Controllers;

use App\Article;
use App\Menu;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Requestst;
use Illuminate\Support\Facades\Input;

class PagesController extends Controller
{
    public function index()
    {
        $article = Article::latest('published_at')->get();
        $data = array(
            'articles' => $article
        );
        return view('pages.index' , compact($data));
    }

    public function contact()
    {
        return view('pages.contact');
    }

    public  function about()
    {
        return view('pages.about');
    }
}

Please help.

Viet Nguyen
  • 2,285
  • 2
  • 26
  • 43
  • 2
    The ide helper is really the best (and only solution) that I know of. I've had no problem getting it working on phpstorm 9. – user1669496 Dec 03 '15 at 19:11
  • Possible duplicate of [PHPStorm is not recognizing methods of my Model class in Laravel 5.0](https://stackoverflow.com/questions/31830077/phpstorm-is-not-recognizing-methods-of-my-model-class-in-laravel-5-0) – Tomáš Staník Sep 30 '19 at 08:20

2 Answers2

1

I ran "php artisan ide-helper:models" -> Yes, it wrote some line in my models file and still not work I ran again "php artisan ide-helper:models" -> No, it created a new file called _ide_helper_models.php file but still not work.

FINALLY

I access file _ide_helper_models.php and add this function into class Article it work xD

/**
 * Add an "order by" clause for a timestamp to the query.
 *
 * @param string $column
 * @return \Illuminate\Database\Query\Builder|static 
 * @static 
 */
public static function latest($column = 'created_at'){
    return \Illuminate\Database\Query\Builder::latest($column);
}
Viet Nguyen
  • 2,285
  • 2
  • 26
  • 43
  • 2
    There is also an option in phpStorm to downgrade severity if __magic methods are present in class. Check in `Settings -> Inspections -> PHP -> Undefined` This will not let you click on the method, but merely disables the annoying markup by as it states, downgrading severity. [Read more about severities here](https://www.jetbrains.com/phpstorm/help/configuring-inspection-severities.html) – ruuter Feb 11 '16 at 18:07
0

Although this is late, I imagine it will found by Googler's when trying to sort this problem even in Laravel 8:

1 composer require --dev barryvdh/laravel-ide-helper

2 php artisan ide-helper:models

3 It will then ask you if it can “Overwrite existing models?” => answer YES it will then add a bunch of PHPdocs tags into the class, it will not actually overwrite the important stuff

WebDev-SysAdmin
  • 269
  • 4
  • 12