我正在尝试播种数据库,但cmd仅返回此FatalThrowableError错误:“找不到类应用程序\产品”
这是我的迁移文件
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = ['imagepath','title','description','price'];
}
这是我的提供商文件
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = ['imagepath','title','description','price'];
}
这是我的种子文件
<?php
use Illuminate\Support\Facades\Product;
use Illuminate\Database\Seeder;
class ProductTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$product=new \app\Product([
'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 \app\Product
类的信息
这是我的SQLSTATE [42S22]的迁移文件,尝试播种时出现问题
<?php
use Illuminate\Support\Facades\Product;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
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分钟,并且我需要相对快地解决此问题,因此我将对此帖子进行编辑。
答案 0 :(得分:2)
名称空间区分大小写\app\Product
应该为\App\Product
也可能有用的是使用命令composer dumpautoload
答案 1 :(得分:1)
您定义了错误的名称空间。将代码更改为此:
public function run()
{
$product=new \App\Product([
'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();
}