Asked  7 Months ago    Answers:  5   Viewed   88 times

I'm using PHP Storm v8.0.3 with the latest version of Laravel.

I'm having trouble making the autocomplete work.

enter image description here

As you can see in the image above.


I have installed barryvdh ide-helper, following the readme he provides on git. I haven't received any errors during its installation.

enter image description here

I have included it in the providers array as either

'BarryvdhLaravelIdeHelperIdeHelperServiceProvider'

or

BarryvdhLaravelIdeHelperIdeHelperServiceProvider:class

It didn't make any difference(as far as I can tell).

I have also installed the Laravel plugin.

Again, no difference, still no auto-complete.

enter image description here

I tried dumping the config file which resulted in:

array:27 [?
 ...
  22 => "IlluminateViewViewServiceProvider"
  23 => "BarryvdhLaravelIdeHelperIdeHelperServiceProvider"
  24 => "AppProvidersAppServiceProvider"
 ...
]

I'm really stuck on this one. I have no idea what could be wrong. Any nudging in the right direction is greatly appreciated.

 Answers

87

Two possible fixes for that:

  1. Make your models extend the Eloquent facade instead of IlluminateDatabaseEloquentModel.
  2. If you prefer to keep using the "Model" facade, you can make your own alias in config/app.php, then change "eloquent" to "model" in the config/ide-helper.php under extra. This will let ide-helper include all the methods from IlluminateDatabaseEloquentBuilder and IlluminateDatabaseQueryBuilder which is where the missing methods actually live.

(Source: https://laracasts.com/discuss/channels/general-discussion/phpstorm-thinks-modelwhere-doesnt-exist-on-model-l5/replies/37661)

Saturday, May 29, 2021
 
subroutines
answered 7 Months ago
33

Ok here is the solution, assuming you have installed the helper already:

Example:

Replace in a controller:

use IlluminateSupportFacadesValidator;

by

  use Validator

In your config/app.php you must have this alias:

'Validator' => IlluminateSupportFacadesValidator::class,

In my case it was already there.

After this, no more error message for the example shown in the image above and I can use full power of phpstorm that correctly understands the ::make method.

Source https://github.com/barryvdh/laravel-ide-helper/issues/431#issuecomment-275898789 thanks @lazyone.

Saturday, May 29, 2021
 
Kevin_Kinsey
answered 7 Months ago
62

You are not passing the current page, like you should so you also get same array. This will work

public function paginate($items,$perPage)
{
    $pageStart = Request::get('page', 1);
    // Start displaying items from this number;
    $offSet = ($pageStart * $perPage) - $perPage; 

    // Get only the items you need using array_slice
    $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);

    return new LengthAwarePaginator($itemsForCurrentPage, count($items), $perPage,Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
}

Your function will also work if you pass correct value for $pageStart - Request::get('page', 1)

Wednesday, August 4, 2021
 
AsGoodAsItGets
answered 4 Months ago
61

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 IlluminateDatabaseQueryBuilder|static 
 * @static 
 */
public static function latest($column = 'created_at'){
    return IlluminateDatabaseQueryBuilder::latest($column);
}
Tuesday, August 24, 2021
 
user3599828
answered 4 Months ago
60

This issue is now resolved as per these github issues:

laravel/tinker#29

bobthecow/psysh#430

The proper solution now is to do composer update

Sunday, August 29, 2021
 
Bitmap
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share