2

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');
    }*/

}    
4
  • how does your site structure look like and do you autoload the necessary files? is your Page model (Page.php) just located in app/models? Commented Feb 6, 2014 at 21:15
  • @Sydney just added the Page Model Commented Feb 6, 2014 at 21:17
  • 2
    Did you run a php composer.phar dumpautoload or composer dumpautoload (depending on your configuration) from your root directory? Commented Feb 6, 2014 at 21:23
  • Added as an answer so you can select it :) Commented Feb 6, 2014 at 21:58

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

}

1 Comment

Thank YOu!!! I was wondering if I can do this much more efficiently! Thank you @Sheikh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.