laravel-modules: Class CreateTestTable located in ./database/Migrations/2021_05_03_093750_create_test_table.php does not comply with psr-4 autoloading standard Skipping.

Hello @all,

I have been trying to understand what this issue is for almost 2 days and hence need your support to understand.

I am using PHPStorm and I have been using 8.1 and updated to 8.2, with the changes now I am getting a warning saying Class CreateTestTable located in ./database/Migrations/2021_05_03_093750_create_test_table.php doesn’t comply with psr-4 autoloading standard.

For Info: I am using the nwidart/laravel-modules(v9) saying that this file is in one of the modules.

here is my composer.json for psr-4 section

 "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "Modules/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
        },
    },

and this is the composer.json in the test module in the directory project/Modules/Test making the directory to root

"autoload": {
        "psr-4": {
            "Modules\\Test\\": ""
        }
    }

This is an issue as I am not able to install the composer into my modules as necessary.

Can anyone help me to understand this?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

You can update your package version to 11 and read the upgrade section.

Also, migrations in the root of the project do not need a namespace (only factories and seeders in the database folder need namespaces). You can remove the namespace and change it to the new migration style:

Example:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Your migration code here
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Your rollback code here
    }
};

With the old version, your folder structure should look like this:

.
├── Database
│   ├── Migrations
│   │   └── 2020_07_21_121709_create_permission_tables.php
│   ├── Seeders
│   │   └── BaseDatabaseSeeder.php
│   └── factories

Ensure that the Database and Migrations folder names are correct (not ‘database’ or ‘migration’).

Check this and share the results.