Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么db:seed返回类应用程序/产品不存在?_Php_Html_Laravel_Laravel Blade - Fatal编程技术网

Php 为什么db:seed返回类应用程序/产品不存在?

Php 为什么db:seed返回类应用程序/产品不存在?,php,html,laravel,laravel-blade,Php,Html,Laravel,Laravel Blade,我正在尝试为我的数据库设置种子,但cmd仅返回此FatalThroWalble错误,即“找不到Class app\Product” 这是我的迁移文件 <?php namespace App; use Illuminate\Database\Eloquent\Model; class Product extends Model { protected $fillable = ['imagepath','title','description','price']; } 这是cm

我正在尝试为我的数据库设置种子,但cmd仅返回此FatalThroWalble错误,即“找不到Class app\Product”

这是我的迁移文件

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = ['imagepath','title','description','price'];
}
这是cmd返回的结果
由于我不能再发布90分钟,并且我需要相对快速地修复此问题,我将编辑此帖子。

名称空间区分大小写
\app\Product
应该是
\app\Product


使用命令
composer dumpautoload

也可能有帮助,因为您定义了错误的命名空间。将代码更改为:

公共函数运行()
{
$product=new\App\product([
'图像路径'=>'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',
“价格”=>“125”
]);
$product->save();
}

我认为您的名称空间有误。请注意,它们区分大小写。App vs App确实有帮助,但现在我发现,您可能忘记迁移了。在控制台中运行此命令:php artisan migrateI之前执行了dumpautoload,然后执行了此操作,它对Migrate没有任何说明这涉及到另一个问题。使用迁移文件创建一篇新文章,以便我们可以尽快帮助您。我不能再发布90分钟,所以我只编辑这篇文章
<?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();
<?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');
    }
}