Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create and configure a Laravel project with PhpStorm

I am quite buzzed with the whole Homestead stuff and how it correlates with an IDE. Let's say I have my PhpStorm installed in ~/Developer/PhpStorm The Homestead is in ~/Developer/Homestead. This is how my YAML file in Homestead looks like:

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 am planning to store my projects, instead of in the Homestead folder.

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

  1. Where exactly should I put the _ide_helper.php file so that PhpStorm works properly with Laravel? Should I paste it in each project or just once somewhere?
  2. Do I have to write a different app name in the YAML sites: map field for every project that I want to be launching atm?
  3. How do I create a new Laravel type project. As when I go for creating a new project in PhpStorm, there are types of which I can choose - should I also have Laravel listed there, because I do not? Because now, when I create a new PHP project - it's completely empty. And I suppose a Laravel project should have some architecture and generated files.
  4. I beg of a simple explanation of all this Laravel + Homestead stuff and Vagrant and how to control my projects, because I am getting very frustrated and I have to start working with these technologies on my Bachelor project soon.
like image 473
Milkncookiez Avatar asked Sep 30 '22 09:09

Milkncookiez


1 Answers

  1. You shouldn't need to put the _ide_helper.php file anywhere manually, it is automatically generated by the Artisan command. For each new project, include the IDE helper in that project's composer.json file:

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

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

    'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'
    

    Then use Artisan to generate 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
    

    This is all paraphrased from the instructions on the IDE Helper GitHub page. I would recommend following those instructions to also set up your composer.json file to auto-generate a new _ide_helper.php whenever composer updates.


  1. Yes. For each individual Laravel project, you'll need to update your sites mapping in the YAML file. For my projects, I use this scheme (note that you are mapping to the 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 your hosts file to point to the Vagrant box.

    sudo nano /etc/hosts
    

    Add the line:

    127.0.0.1           local.project.example.com
    

    Now you should be able to access this Laravel project by hitting: local.project.example.com:8000 in your web browser.


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

    laravel new blog
    

  1. I hope the above answers get you started down the right path. The most important thing is to carefully read the Laravel documentation as it covers everything I just did but in much greater detail.
like image 175
Mike Andersen Avatar answered Oct 16 '22 19:10

Mike Andersen