Question

This is my 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,
    ));                
}

}

after running "php artisan db:seed" My first file works but not the second and i don't understand why.

Here is the following message:

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

Here is my Page model located in app/models/Page.php

<?php
namespace App\Models;

class Page extends \Eloquent {

    protected $table = 'pages';

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

}    
Was it helpful?

Solution

It seems that you didn't update your Composer's autoload file. Any time you add a class to be called throughout Laravel, it needs to be included as a page loads. This can be done manually with an include() or require(), but you can also run php composer.phar dumpautoload (or composer autoload) to update which files are automatically loaded on each page. This needs to be done every time a class is added.

See Composer's autoloading documentation for more info.

OTHER TIPS

It seems that, the problem has been solved but I just would like to mention that you may also use something like this:

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);
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top