Create and set up a Laravel project with PhpStorm

I'm pretty buzzing with all of the Homestead stuff and how it relates to the IDE. Say I have installed PhpStorm in ~/Developer/PhpStorm The Homestead is in ~/Developer/Homestead . Here's what my YAML file looks like in Homestead:

 authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: ~/Developer/Homestead/workspace to: /home/vagrant/Code sites: - map: helloworld.app to: /home/vagrant/Code/Laravel/public variables: - key: APP_ENV value: local 

So you see that I have a workspace folder in the Homestead directory. I also have another directory: ~/Developer/workspace/PHP , where I plan to store my projects, and not in the Homestead folder.

I installed the Laravel plugin in PhpStorm. And for the Laravel plugin to work in PhpStorm, this generated file is needed. My questions:

  • Where exactly should I put the _ide_helper.php file for PhpStorm to work correctly with Laravel? Should I embed it in every project or just somewhere?
  • Should I write a different application name in the YAML sites: map field for each project that I want to run atm?
  • How to create a new project like Laravel. As in the case of creating a new project in PhpStorm, there are options that I can choose - should I also include Laravel there, because I do not? Because now when I create a new PHP project, it is completely empty. And I believe that the Laravel project should have some architecture and generated files.
  • I am asking for a simple explanation of all this material by Laravel + Homestead and Vagrant and how to control my projects because I am very upset and I should start working with these technologies in my Bachelor project in the near future.
+5
source share
2 answers
  • You do not need to place the _ide_helper.php file anywhere manually, it is automatically generated by the Artisan team. For each new project, include the IDE helper in the composer.json project file:

     "require-dev": { "barryvdh/laravel-ide-helper": "1.*" } 

    Add the service provider to the providers array in the config.php your Laravel project:

     'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' 

    Then use Artisan to create the _ide_helper.php file for the project (run this command from the terminal in the root of your Laravel project directory):

     php artisan ide-helper:generate 

    All of these are rephrased from the instructions on the IDE Helper GitHub page. I would recommend following these instructions to also configure your composer.json file to automatically create a new _ide_helper.php when updating the composer.


  1. Yes. For each individual Laravel project, you need to update your site mapping in the YAML file. For my projects, I use this scheme (note that you map it to a location relative to your Vagrant box):

     sites: - map: local.project.example.com to: /home/vagrant/Projects/project/public 

    Then in your Homestead directory, run:

     vagrant provision 

    You will also need to update the hosts file to indicate the Vagrant field.

     sudo nano /etc/hosts 

    Add a line:

     127.0.0.1 local.project.example.com 

    You should now have access to this Laravel project by clicking local.project.example.com:8000 in your web browser.


    1. Assuming you follow the instructions of Laravel , the easiest way is to use the Laravel command in the terminal. To create a new Laravel project called a "blog", go to ~/Developer/workspace/PHP and run the command:

       laravel new blog 

      1. Hope the answers above help you get started on the right track. The most important thing is to carefully read the Laravel documentation, as it covers everything that I just did, but in more detail.
+4
source

thanks to Mike Andersen, you put me on the right track, but your number 1 solution doesn't work for me (using Laravel 5).

You need to run "composer update" after making changes to the composer.json file. But, when I did, I got this error:

 barryvdh/laravel-ide-helper v1.2.1 requires phpdocumentor/reflection-docblock dev-master#6d705c1a0f9e2a6d73d2e9ec0e538b9dfaf4315f -> no matching package found. 

I have another solution:

  • remove the line about "barryvdh / laravel-ide-helper" from the require array on the composer.json file.
  • run the following line: composer require barryvdh/laravel-ide-helper

Then you can follow the steps suggested by Mike Andersen:

  1. Add the service provider to the providers array in the config.php file of your Laravel project:

    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider

  2. Then use Artisan to create the _ide_helper.php file for the project (run this command from the terminal in the root of your Laravel project directory):

    php artisan ide-helper:generate

  3. Open the project on phpStorm and go to: File|Synchronize .

And you will get an updated laravel project with the latest version of the extension barryvdh / laravel-ide-helper

(Additional info: https://github.com/barryvdh/laravel-ide-helper )

0
source

Source: https://habr.com/ru/post/1207304/


All Articles