播种时未找到Laravel PHP致命错误类

时间:2014-02-06 21:10:46

标签: laravel cartalyst-sentry

这是我的ContentSeeder.php

 <?php

 use App\Models\Page;

 class ContentSeeder extends Seeder {

public function run()
{
    DB::table('pages')->delete();

    Page::create(array(
        'title'   => 'About us',
        'slug'    => 'about-us',
        'body'    => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'user_id' => 1,
    ));

    Page::create(array(
        'title'   => 'Privacy Policy',
        'slug'    => 'privacy-policy',
        'body'    => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'user_id' => 1,
    ));

    Page::create(array(
        'title'   => 'Terms of Use',
        'slug'    => 'terms-of-use',
        'body'    => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'user_id' => 1,
    ));                
}

}

运行“php artisan db:seed”后我的第一个文件有效,但不是第二个,我不明白为什么。

以下是以下信息:

PHP Fatal error: Class 'App\Models\Page' not found in C:\wamp\www\mysite\app\database\seeds\ContentSeeder.php on line 11

这是我的页面模型,位于app / models / Page.php

<?php
namespace App\Models;

class Page extends \Eloquent {

    protected $table = 'pages';

    /*public function author()
    {
        return $this->belongsTo('User');
    }*/

}    

2 个答案:

答案 0 :(得分:6)

您似乎没有更新Composer的自动加载文件。每次添加要在整个Laravel中调用的类时,都需要将其作为页面加载包含在内。这可以使用include()require()手动完成,但您也可以运行php composer.phar dumpautoload(或composer autoload)来更新每个页面上自动加载的文件。这需要在每次添加课程时完成。

有关详细信息,请参阅Composer's autoloading文档。

答案 1 :(得分:1)

似乎问题已经解决,但我想提一下你也可以使用这样的东西:

class ContentSeeder extends Seeder {

    public function run()
    {
        $pages = array(

            array(
                'title'   => 'About us',
                'slug'    => 'about-us',
                'body'    => 'Lorem...',
                'user_id' => 1,
            ),

            array(
                'title'   => 'Privacy Policy',
                'slug'    => 'privacypolicy',
                'body'    => 'Lorem...',
                'user_id' => 1,
            )

            // more...
        );

        DB::table('pages')->delete();
        DB::table('pages')->insert($pages);
    }

}