spatie / laravel-multitenancy

Make your Laravel app usable by multiple tenants
https://spatie.be/docs/laravel-multitenancy
MIT License
1.11k stars 153 forks source link

unable to publish or run landlord migration Laravel 8.12 #211

Closed malsgit closed 3 years ago

malsgit commented 3 years ago

When running the follow: php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="migrations" I get the following error Unable to locate publishable resources I can select via list using php artisan vendor:publish but then creates the following folder 2021_03_19_161553_landlord and file inside create_landlord_tenants_table.php

If I then run the following as per v2 docs, I get an error php artisan migrate --path=database/migrations/landlord --database=landlord if I change the --path to php artisan migrate --path=database/migrations/2021_03_19_161553_landlord --database=landlord

I get the following error in the terminal

Error 

  Class "" not found

  at vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:453
    449▕     public function resolve($file)
    450▕     {
    451▕         $class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
    452▕ 
  ➜ 453▕         return new $class;
    454▕     }
    455▕ 
    456▕     /**
    457▕      * Get all of the migration files in a given path.

      +19 vendor frames 
  20  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

After looking at the Scheme::create part it is just putting ('tenants'...... I renamed folder to landlord and running php artisan make:migration CreateLandlordTenantsTable --path=database/migrations/landlord and adding the following to public function up

       ```

$table->string('name'); $table->string('domain')->unique(); $table->string('database')->unique();


ran `php artisan migrate --path=database/migrations/landlord --database=landlord` again and this time it worked!!!
masterix21 commented 3 years ago

Hi @malblack. Try with:

php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="multitenancy-migrations"
malsgit commented 3 years ago

that creates

Hi @malblack. Try with:

php artisan vendor:publish --provider="Spatie\Multitenancy\MultitenancyServiceProvider" --tag="multitenancy-migrations"

That shell command creates the following path: database>migrations>2021_03_191136_landlord>create_landlord_tenants_table.php

I think it should be database>migrations>landlord>2021_03_191136_create_landlord_tenants_table.php

I think it is something to do with the following code in the vendor>spatie>laravel=package-tools>PackageServiceProvider.php

$now = now();
            foreach ($this->package->migrationFileNames as $migrationFileName) {
                if (! $this->migrationFileExists($migrationFileName)) {
                    $this->publishes([
                        $this->package->basePath("/../database/migrations/{$migrationFileName}.php.stub") => database_path('migrations/' . $now->addSecond()->format('Y_m_d_His') . '_' . Str::finish($migrationFileName, '.php')),
                    ], "{$this->package->shortName()}-migrations");
                }
            }

but I don't know how to change it to give the correct path, to run the landlord migration command

masterix21 commented 3 years ago

Sorry, but I think that the migration path should be project-by-project. For example, using a single-database tenant approach, you won't need to move your migrations into an isolated path.

The package couldn't cover all requirements but helps everyone: with or without small changes.

malsgit commented 3 years ago

@masterix21 that's is fine, I just changed the migration folder and file name then ran it all works perfect now :-) and very impressed with it......

masterix21 commented 3 years ago

Great ;) Happy coding :)

zoxed commented 3 years ago

when i try to do : php artisan migrate --path=database/migrations/landlord --database=landlord je reçois cette erreur : // PS C:\laragon\www\commerce> php artisan migrate:fresh --path=database/migrations/landlord --database=landlord


Dropped all tables successfully.

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table ` (idint unsigned not null auto_increment primary key,migrationvarchar(191) not null,batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci' engine = InnoDB)

at C:\laragon\www\commerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) {

671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675|

1 C:\laragon\www\commerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exception.php:18 Doctrine\DBAL\Driver\PDO\Exception::("SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''")

2 C:\laragon\www\commerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:84 Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException)) PS C:\laragon\www\commerce>