В моем приложении laravel 5.7 в консоли я создал новый скрипт переноса таблицы и сеялку:
php artisan make:migration create_page_content_images_table --create="page_content_images"
php artisan make:seeder PageContentImagesWithInitData
Оба файла были созданы нормально, и я заполнил их database / migrations / 2018_12_04_120422_create_page_content_images_table.php:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePageContentImagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('page_content_images', function (Blueprint $table) {
$table->increments('id');
$table->integer('page_content_id')->unsigned();
$table->foreign('page_content_id')->references('id')->on('page_contents')->onDelete('RESTRICT');
$table->string('filename', 255);
$table->boolean('is_main')->default(false);
$table->boolean('is_video')->default(false);
$table->string('video_type', 10)->nullable();
$table->string('video_ext', 5)->nullable();
$table->smallInteger('video_width')->nullable();
$table->smallInteger('video_height')->nullable();
$table->string('info', 255)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->unique(['page_content_id', 'filename'], 'page_contents_page_content_id_filename_unique');
$table->index(['page_content_id', 'is_main'], 'page_contents_page_content_id_is_main');
$table->index(['page_content_id', 'is_video', 'filename'], 'page_contents_page_content_id_is_video_filename');
$table->index(['created_at'], 'page_content_message_documents_created_at_index');
});
Artisan::call('db:seed', array('--class' => 'PageContentImagesWithInitData')); //database/seeds/PageContentImagesWithInitData.php
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('page_content_images');
}
}
и database / seed / PageContentImagesWithInitData.php:
<?php
use Illuminate\Database\Seeder;
class PageContentImagesWithInitData extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('page_content_images')->insert([
'id' => 1,
'page_content_id' => 1, // About
'filename' => 'your_vote.jpg',
'is_main' => false,
'is_video' => false,
'video_type' => null,
'video_ext' => null,
'video_width' => null,
'video_height' => null,
'info' => 'Site slogan image',
]);
DB::table('page_content_images')->insert([
'id' => 2,
'page_content_id' => 1, // About
'filename' => 'our_boss.jpg',
'is_main' => false,
'is_video' => false,
'video_type' => null,
'video_ext' => null,
'video_width' => null,
'video_height' => null,
'info' => 'Our boss photo',
]);
DB::table('page_content_images')->insert([
'id' => 3,
'page_content_id' => 1, // About
'filename' => 'our_main_manager.jpg',
'is_main' => false,
'is_video' => false,
'video_type' => null,
'video_ext' => null,
'video_width' => null,
'video_height' => null,
'info' => 'Our main manager',
]);
DB::table('page_content_images')->insert([
'id' => 4,
'page_content_id' => 2, // Contact Us
'filename' => 'office_building.jpeg',
'is_main' => true,
'is_video' => false,
'video_type' => null,
'video_ext' => null,
'video_width' => null,
'video_height' => null,
'info' => 'Office building',
]);
DB::table('page_content_images')->insert([
'id' => 5,
'page_content_id' => 2, // Contact Us
'filename' => 'office.jpeg',
'is_main' => true,
'is_video' => false,
'video_type' => null,
'video_ext' => null,
'video_width' => null,
'video_height' => null,
'info' => 'Our Office',
]);
}
}
Проблема в том, что при выполнении команды миграции я получил ошибку:
ReflectionException : Class PageContentImagesWithInitData does not exist
at /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
Я проверил и не вижу орфографических ошибокили проблема ... Я запускаю в консоли следующие команды:
php artisan config:cache
composer dump-autoload
Но я все равно получаю ошибку ...
Почему ошибка и как ее исправить?
Спасибо!