简体   繁体   English

Laravel Artisan发出命令问题

[英]Laravel Artisan make command issue

I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below. 我正在尝试使用artisan php artisan make:middleware AuthorizedUserOnly来制作中间件php artisan make:middleware AuthorizedUserOnlyErrorException如下所示的ErrorException

file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory. file_get_contents(/mysite.com/www/local/composer.json)无法打开流,没有此类文件或目录。

This is my document root. 这是我的文档根目录。

-local
  -Laravel application folders
  -artisan
-index.php
-composer.json
.htaccess

I changed my directory structure to work with shared hosting. 我更改了目录结构以使用共享主机。 And It was working fine. 而且工作正常。

KEY NOTES 重点说明

  1. Other artisan commands work. 其他artisan命令也可以工作。 Like I tried php artisan route:list & php artisan config:cache & php artisan tinker . 就像我尝试过php artisan route:listphp artisan config:cachephp artisan tinker
  2. This directory structure works fine.But as the error says that it is trying to find composer.json in local directory while it is on document root . 这个目录结构工作正常。但是由于错误,它试图在document root目录上的local目录中查找composer.json
  3. php artisan make:model command spits the same Exception php artisan make:model命令吐出同样的Exception

What could be the possible issue and solution ? 可能的问题和解决方案是什么?

Solution : I moved my composer.json file to local directory and it worked fine. 解决方案 :我将composer.json文件移动到local目录,并且工作正常。 So new directory structure is 所以新的目录结构是

-local
  -Laravel Application Folders
  -composer.json
  -artisan
-index.php
.htaccess

HOW ? 怎么样

I am not sure about this yet. 我还不确定。 But this is the possible reason. 但这是可能的原因。 php artisan make command create some files. php artisan make命令创建一些文件。 So to included these created files into system execute composer dump-autoload . 因此要将这些创建的文件包含到系统中,请执行composer dump-autoload So to run composer it looks for in the same directory where artisan lives which is local directory in my case. 因此,要运行composer它会在artisan所在的目录中查找local目录(本例中为local目录)。

IMPORTANT 重要

I changed laravel default directory structure to successfully run my applicaiton on SHARED HOSTING which laravel DOESNOT RECOMMEND . 我更改了laravel默认目录结构,以在LARavel 不推荐的 SHARED HOSTING上成功运行我的应用程序。

We should follow the recommendations made by laravel to avoid any similiar issue. 我们应该遵循laravel提出的建议,以避免任何类似的问题。 Specially never to mess with default directory structure at least. 特别是至少不要搞乱默认目录结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM