仍然不完全明白我是如何得到這個工作,但對於其他人;
在你的PackagenameServiceProvider
使用$this->publishes()
的種子和遷移轉到基本應用
public function boot()
{
if (!$this->app->routesAreCached()) {
require __DIR__.'/../routes.php';
}
$this->publishes([
__DIR__.'/../DatabaseStuff/Migrations' => $this->app->databasePath().'/migrations',
__DIR__.'/../DatabaseStuff/Seeds/Example1Seeder.php' => $this->app->databasePath().'/seeds/Example1Seeder.php',
__DIR__.'/../DatabaseStuff/Seeds/Example2Seeder.php' => $this->app->databasePath().'/seeds/Example2Seeder.php',
]);
}
的boot
方法有DatabaseSeeder
與call
方法指向的種子要運行,但要確保它的副本名稱間隔正確的位置,以確保您的軟件包中有文件。
namespace ExampleVendor\ExamplePackage\DatabaseStuff;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call(\Example1Seeder::class);
$this->call(\Example2Seeder::class);
Model::reguard();
}
}
現在運行以下命令。在這種情況下關鍵命令對我來說是php artisan optimize
php artisan vendor:publish
composer dump-autoload
php artisan cache:clear
php artisan optimize
php artisan db:seed --class="ExampleVendor\ExamplePackage\DatabaseStuff\DatabaseSeeder"
沒有php artisan optimize
我一直得到
ReflectionException
Class ExampleVendor\ExamplePackage\DatabaseStuff\DatabaseSeeder does not exist
希望這可以幫助別人的未來。
爲什麼你甚至希望用戶種子/遷移:刷新它似乎不是真正安全的做到這一點。但是您可以將您想要種子的內容轉儲到工作中或在腳本中執行命令。 – Joost
我們公司將項目創建爲包,這樣我們就可以輕鬆地將項目拉到其他項目中,最多隻需一行添加和腳本。我想在基本應用程序中保持一行更改。你指的是什麼命令? – myol