3

I decided to use PhpStorm for my new Laravel project, so I thought I wanted some autocompletion. I did read the guide from https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/ and some of it works fine, but I got a problem.

I wanted to test my DB connection, so I just made a simple index() function like this

if(DB::connection()->getDatabaseName()) {
    echo 'Connected to ' . DB::connection()->getDatabaseName();
}

Which works fine, but when I write DB and press Tab I write \DB:: instead of DB::. Then I include use Illuminate\Support\Facades\DB; and DB:: works. But when I added the facade, the autocompletion isn't the same at all and it cant find the methods but they works. It's really annoying.

Someone else had this problem and is there a solution for it?

4 Answers 4

13

In PhpStorm, Settings => plugins

  • Search repository for laravel and install.

Then after add this package:

composer require barryvdh/laravel-ide-helper

You can find more help on github for this package:https://github.com/barryvdh/laravel-ide-helper

Sign up to request clarification or add additional context in comments.

Comments

8

First, install the Laravel plugin for PhpStorm, then install laravel-ide-helper. After that, generate ide-helper for your project)

php artisan ide-helper:generate
php artisan ide-helper:meta

For correct autocomplete model you must identify this model use (model namespace)

3 Comments

Still adds backslach infront of DB unless i use the facades one. But if i 'use Illuminate\Support\Facades\DB' then autocompletion for that one doenst work. Can like DB::connection in the tab (it works in the code)
For this you must write the use (use DB). After that DB::connection work in tab (i try it in my storm :) )
Strom must identify the model and than load autocomplete data (methods, variables and consts of this model)
2

You have to install the helpers - https://github.com/barryvdh/laravel-ide-helper

2 Comments

Already did. And i did add it as a serviceprovider and then ide-helper:generate, but didnt solve the problem
does _ide-helper.php appeared in project root? Should be so. You also should have in top of your file. use Illuminate\Support\Facades\DB; You may also wish to install phpstorm plugin called laravel - it also helps
-2

Figured it out :) Just att DB to your class and the problem is solved.

use DB;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.