Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 DatabaseSeed.php throws class not found

I have tried so much to get this database seed to work but I still get Class 'Account' not found even though I have namespaced where I should.

There error is thrown when running php artisan db:seed on $accountOut = Account::create(array( where Account is what is throwing the error. Am stating the using incorrectly? If I were to remove all the namespacing I have no issues at all.

My Account.php file:

<?php namespace App\Models;

class Account extends \Eloquent {

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'account';

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

My seed file:

<?php

use App\Models;

class TransactionSeeder extends Seeder {

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

    $accountOut = Account::create(array(
        'name'    => 'Checking',
        'origin'  => 'Bank'
    ));

    $accountIn = Account::create(array(
        'name'    => 'Stuff',
        'origin'  => 'Expense'
    ));

    $adminUser  = Sentry::getUserProvider()->findByLogin('[email protected]');

    Transaction::create(array(
        'account_id_in'   => $accountIn->id,
        'account_id_out'    => $accountOut->id,
        'amount'    => 300.00
    ));

}

}
like image 489
tuck Avatar asked Dec 13 '25 05:12

tuck


2 Answers

I feel really stupid but instead of calling out use App\Models you would call out use App\Models\Account and it works as it should.

Then remember to run php composer.phar dump-autoload

like image 149
tuck Avatar answered Dec 16 '25 00:12

tuck


I've had similar issues and prefixing my classes with the namespace operator solved them.

Try \Account

like image 38
Cody Caughlan Avatar answered Dec 15 '25 23:12

Cody Caughlan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!