为什么DB:种子返回类应用程序/产品不存在



我正在尝试播种我的数据库,但是cmd只是返回了"找不到class app product"

这是我的迁移文件

<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Product extends Model
{
    protected $fillable = ['imagepath','title','description','price'];
}

这是我的提供者文件

<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Product extends Model
{
    protected $fillable = ['imagepath','title','description','price'];
}

这是我的播种机文件

<?php
use IlluminateSupportFacadesProduct;
use IlluminateDatabaseSeeder;
class ProductTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $product=new appProduct([
            'imagepath' =>'https://cdn.djcity.com.au/wp-content/uploads/2016/07/14082413/launchkey-mini-elevated_0.jpg',
            'title' =>'Novation LaunchKey Mini mk2 MIDI',
            'description' =>'issa book',
            'price' =>'125'
        ]);
        $product ->save();

cmd只是返回,找不到$product=new appProduct

这是我的sqlstate [42S22]问题的迁移文件,当我尝试播种

<?php
use IlluminateSupportFacadesProduct;
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('product', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();
            $table->string('imagePath');
            $table->string('title');  
            $table->text('description');
            $table->integer('price');    
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}

这就是CMD返回的CMD由于我不能再发布90分钟,因此我需要修复此相对较快的时间,所以我将编辑此帖子。

名称空间是案例敏感的 appProduct应该是 AppProduct

也可能会有所帮助的是使用命令composer dumpautoload

您已经定义了错误的名称空间。更改代码:

public function run()
{
    $product=new AppProduct([
        'imagepath' =>'https://cdn.djcity.com.au/wp-content/uploads/2016/07/14082413/launchkey-mini-elevated_0.jpg',
        'title' =>'Novation LaunchKey Mini mk2 MIDI',
        'description' =>'issa book',
        'price' =>'125'
    ]);
    $product ->save();
}

最新更新