使用 PhpStorm 创建和配置 Laravel 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27041371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create and configure a Laravel project with PhpStorm
提问by Milkncookiez
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:
我对 Homestead 的所有内容以及它与 IDE 的关联非常感兴趣。假设我在~/Developer/PhpStorm
The Homestead 中安装了我的 PhpStorm ~/Developer/Homestead
。这是我在 Homestead 中的 YAML 文件的样子:
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.
所以,你会看到我在 Homestead 目录中有一个工作区文件夹。我还有另一个目录:~/Developer/workspace/PHP
我打算在其中存储我的项目,而不是在 Homestead 文件夹中。
I installed the Laravel plugin in PhpStorm. And, in order for the Laravel plugin to work in PhpStorm, this generated fileis needed. My questions are:
我在 PhpStorm 中安装了 Laravel 插件。而且,为了让 Laravel 插件在 PhpStorm 中工作,需要这个生成的文件。我的问题是:
- 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? - Do I have to write a different app name in the YAML sites: mapfield for every project that I want to be launching atm?
- 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.
- 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.
- 我应该把
_ide_helper.php
文件放在哪里,以便 PhpStorm 与 Laravel 正常工作?我应该将它粘贴到每个项目中还是只粘贴一次? - 我是否必须在 YAML站点中编写不同的应用程序名称:我要启动 atm 的每个项目的地图字段?
- 如何创建一个新的 Laravel 类型项目。当我在 PhpStorm 中创建一个新项目时,我可以选择多种类型 - 我是否也应该在那里列出 Laravel,因为我没有列出?因为现在,当我创建一个新的 PHP 项目时 - 它完全是空的。我认为 Laravel 项目应该有一些架构和生成的文件。
- 我想对所有这些 Laravel + Homestead 的东西和 Vagrant 以及如何控制我的项目做一个简单的解释,因为我感到非常沮丧,我必须尽快开始在我的学士项目中使用这些技术。
采纳答案by Mike Andersen
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'scomposer.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.
您不需要
_ide_helper.php
手动将文件放在任何地方,它是由 Artisan 命令自动生成的。对于每个新项目,在该项目的composer.json
文件中包含 IDE 帮助程序:"require-dev": { "barryvdh/laravel-ide-helper": "1.*" }
将服务提供者添加到
config.php
Laravel 项目文件中的 providers 数组中:'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider'
然后使用 Artisan
_ide_helper.php
为项目生成文件(从 Laravel 项目目录根目录中的终端运行此命令):php artisan ide-helper:generate
这都是从IDE Helper GitHub 页面上的说明转述的。我建议按照这些说明设置你的 composer.json 文件,以便
_ide_helper.php
在 composer 更新时自动生成一个新文件。
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.
是的。对于每个单独的 Laravel 项目,您需要更新 YAML 文件中的站点映射。对于我的项目,我使用这个方案(请注意,您正在映射到相对于您的 Vagrant 框的位置):
sites: - map: local.project.example.com to: /home/vagrant/Projects/project/public
然后在你的 Homestead 目录中,运行:
vagrant provision
您还需要更新您的主机文件以指向 Vagrant 框。
sudo nano /etc/hosts
添加行:
127.0.0.1 local.project.example.com
现在你应该可以通过
local.project.example.com:8000
在你的网络浏览器中点击:来访问这个 Laravel 项目。
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
假设您按照Laravel 安装说明进行操作,最简单的方法是在终端中使用 Laravel 命令。要创建一个名为“blog”的新 Laravel 项目,请导航到
~/Developer/workspace/PHP
并运行以下命令:laravel new blog
- 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.
- 我希望以上答案能让您走上正确的道路。最重要的是仔细阅读 Laravel 文档,因为它涵盖了我刚刚所做的一切,但更详细。
回答by Juan Antonio Tubío
thanks Mike Andersen, you have put me on correct way, but your solution number 1 don't work for me (using Laravel 5).
谢谢 Mike Andersen,你让我走上了正确的道路,但你的解决方案 1 对我不起作用(使用 Laravel 5)。
You have to run "composer update"
after making changes to composer.json file. But, when i have doed, i got this error:
您必须"composer update"
在对 composer.json 文件进行更改后运行。但是,当我这样做时,我收到了这个错误:
barryvdh/laravel-ide-helper v1.2.1 requires phpdocumentor/reflection-docblock dev-master#6d705c1a0f9e2a6d73d2e9ec0e538b9dfaf4315f -> no matching package found.
I have got another solution:
我有另一个解决方案:
- remove line about "barryvdh/laravel-ide-helper" from require array on composer.json file.
- run the next line:
composer require barryvdh/laravel-ide-helper
- 从 composer.json 文件的 require 数组中删除有关“barryvdh/laravel-ide-helper”的行。
- 运行下一行:
composer require barryvdh/laravel-ide-helper
Then you can follow the steps proposed by Mike Andersen:
然后您可以按照 Mike Andersen 提出的步骤进行操作:
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
Open your project on phpStorm and go to:
File|Synchronize
.
将服务提供者添加到 Laravel 项目的 config.php 文件中的 providers 数组中:
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider
然后使用 Artisan 为项目生成 _ide_helper.php 文件(从 Laravel 项目目录根目录中的终端运行此命令):
php artisan ide-helper:generate
在 phpStorm 上打开您的项目并转到:
File|Synchronize
。
And you will got your laravel project updated with the last version of barryvdh/laravel-ide-helper extension
您将使用最新版本的 barryvdh/laravel-ide-helper 扩展更新您的 Laravel 项目
(More info: https://github.com/barryvdh/laravel-ide-helper)