Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Naumanz's avatar

Issue with artisan make command.

I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below.

file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory.

This is my document root.

-local
   -Laravel application folders
-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. Like I tried php artisan route:list & php artisan config:cache & php 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.
  3. php artisan make:model command spits the same Exception

What could be the possible issue and solution ?

0 likes
3 replies
Snapey's avatar

Its probably this

vendor/laravel/framework/src/Illuminate/Foundation/Application.php

/**
     * Get the application namespace.
     *
     * @return string
     *
     * @throws \RuntimeException
     */
    public function getNamespace()
    {
        if (! is_null($this->namespace)) {
            return $this->namespace;
        }

        $composer = json_decode(file_get_contents(base_path('composer.json')), true);

        foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
            foreach ((array) $path as $pathChoice) {
                if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) {
                    return $this->namespace = $namespace;
                }
            }
        }

        throw new RuntimeException('Unable to detect application namespace.');
    }

I imagine its an issue for all the make commands

Its only making boilerplate for you so you could create the file yourself, or have a regular project and copy it from there

However, with that directory structure you are really on your own because it is non-standard and probably a big security risk.

Naumanz's avatar

Hi @Snapey , Yes it is also for all make commands. I am new to Laravel. Can you please explain this a bit more.

Thanks.

Please or to participate in this conversation.