I'm a newbie in Laravel and and I'm teaching myself how to authenticate from a login table. I have migrated and created the table. Now, I'm trying to seed the data into the login table, but the command prompt is continuously giving me error, which says Fatal Error, class login not found
and I have no idea what i have missed. So can anyone please help me. Here is the code that i have, and yes I'm using Laravel 4.3
我是Laravel的新手,我正在教自己如何从登录表进行身份验证。我已经迁移并创建了表格。现在,我正在尝试将数据播种到登录表中,但命令提示符不断给出错误,其中显示致命错误,未找到类登录,我不知道我错过了什么。所以任何人都可以帮助我。这是我的代码,是的,我正在使用Laravel 4.3
<?php
class loginTableSeeder extends Seeder
{
public function run()
{
DB::table('login')->delete();
login::create(array(
'username' => 'sanju',
'password' => Hash::make('sanju')
));
}
}
?>
6 个解决方案
#1
7
You need to create an Eloquent model for that table in order to use Login::create()
. You can do that with a simple artisan command:
您需要为该表创建一个Eloquent模型才能使用Login :: create()。你可以用一个简单的工匠命令来做到这一点:
$ php artisan generate:model Login
$ php artisan generate:model登录
This will generate a new Eloquent model in app/models
directory which should look like this.
这将在app / models目录中生成一个新的Eloquent模型,该模型应如下所示。
class Login extends Eloquent {
protected $fillable = [];
protected $table = 'login';
}
Your code should work after that. If it still doesn't make sure you run composer dump-autoload
.
你的代码应该在那之后工作。如果仍然无法确保您运行composer dump-autoload。
#2
14
EDIT
编辑
Now I see, the problem is with your login
class (with earlier question formatting the exact error was illegible). You should look again what's the name of file where you have login
class and what's the name of class. The convention is that the file should have name Login.php
(with capital letter) and the name of class also should be Login
(with capital letter). You should also check in what namespace is your Login
class. If it is defined in in App
namespace, you should add to your LoginTableSeeder
:
现在我看到,问题在于您的登录类(早期的问题格式化确切的错误是难以辨认的)。你应该再看一下你有登录类的文件名是什么,以及什么是类的名称。惯例是文件应该具有名称Login.php(带有大写字母),类的名称也应该是Login(带大写字母)。您还应该检查您的Login类是什么命名空间。如果在App命名空间中定义,则应添加到LoginTableSeeder:
use App\Login;
in the next line after <?php
在<?php之后的下一行
so basically the beginning of your file should look like this:
所以基本上你的文件的开头应该是这样的:
<?php
use App\Login;
use Illuminate\Database\Seeder;
EARLIER ANSWER
更早的回答
You didn't explained what the exact error is (probably the error is for Seeder
class) but:
您没有解释确切的错误是什么(可能错误是Seeder类)但是:
In database/seeds/DatabaseSeeder.php
you should run Login seeder like this:
在database / seeds / DatabaseSeeder.php中你应该像这样运行Login seeder:
$this->call('LoginTableSeeder');
You should put into database/seeds
file LoginTableSeeder.php
with capital letter at the beginning.
您应该在开头使用大写字母放入数据库/种子文件LoginTableSeeder.php。
Now, your file LoginTableSeeder.php
file should look like this:
现在,您的文件LoginTableSeeder.php文件应如下所示:
<?php
use Illuminate\Database\Seeder;
class LoginTableSeeder extends Seeder
{
public function run()
{
// your code goes here
}
}
you need to import Seeder
with use
at the beginning of file and again class name should start with capital letter.
你需要在文件的开头导入Seeder,并且类名应该以大写字母开头。
Now you should run composer dump-autoload
and now when you run php artisan db:seed
it will work fine.
现在你应该运行composer dump-autoload,现在当你运行php artisan db:seed它会正常工作。
#3
8
Just run composer dump-autoload -o
for the autoloader to pick up the newly classes because the database folder is not automatically autoloaded with PSR-4.
只需为自动加载器运行composer dump-autoload -o以获取新类,因为数据库文件夹不会自动使用PSR-4自动加载。
#4
2
This worked for me
这对我有用
composer dump-autoload -o
#5
1
I have the same problem but you can solve it by adding your namespace:
我有同样的问题,但你可以通过添加你的命名空间来解决它:
namespace yournamespace;
use App\Login;
use Illuminate\Database\Seeder;
#6
0
I've experienced the same problem. In my case, the composer was extremely old and after it's update everything runs Ok.
我遇到了同样的问题。在我的情况下,作曲家非常古老,在更新之后一切都运行正常。
Update composer with the command:
使用以下命令更新composer:
$ composer self-update
$ composer自我更新
Hope it can help others.
希望它可以帮助别人。
#1
7
You need to create an Eloquent model for that table in order to use Login::create()
. You can do that with a simple artisan command:
您需要为该表创建一个Eloquent模型才能使用Login :: create()。你可以用一个简单的工匠命令来做到这一点:
$ php artisan generate:model Login
$ php artisan generate:model登录
This will generate a new Eloquent model in app/models
directory which should look like this.
这将在app / models目录中生成一个新的Eloquent模型,该模型应如下所示。
class Login extends Eloquent {
protected $fillable = [];
protected $table = 'login';
}
Your code should work after that. If it still doesn't make sure you run composer dump-autoload
.
你的代码应该在那之后工作。如果仍然无法确保您运行composer dump-autoload。
#2
14
EDIT
编辑
Now I see, the problem is with your login
class (with earlier question formatting the exact error was illegible). You should look again what's the name of file where you have login
class and what's the name of class. The convention is that the file should have name Login.php
(with capital letter) and the name of class also should be Login
(with capital letter). You should also check in what namespace is your Login
class. If it is defined in in App
namespace, you should add to your LoginTableSeeder
:
现在我看到,问题在于您的登录类(早期的问题格式化确切的错误是难以辨认的)。你应该再看一下你有登录类的文件名是什么,以及什么是类的名称。惯例是文件应该具有名称Login.php(带有大写字母),类的名称也应该是Login(带大写字母)。您还应该检查您的Login类是什么命名空间。如果在App命名空间中定义,则应添加到LoginTableSeeder:
use App\Login;
in the next line after <?php
在<?php之后的下一行
so basically the beginning of your file should look like this:
所以基本上你的文件的开头应该是这样的:
<?php
use App\Login;
use Illuminate\Database\Seeder;
EARLIER ANSWER
更早的回答
You didn't explained what the exact error is (probably the error is for Seeder
class) but:
您没有解释确切的错误是什么(可能错误是Seeder类)但是:
In database/seeds/DatabaseSeeder.php
you should run Login seeder like this:
在database / seeds / DatabaseSeeder.php中你应该像这样运行Login seeder:
$this->call('LoginTableSeeder');
You should put into database/seeds
file LoginTableSeeder.php
with capital letter at the beginning.
您应该在开头使用大写字母放入数据库/种子文件LoginTableSeeder.php。
Now, your file LoginTableSeeder.php
file should look like this:
现在,您的文件LoginTableSeeder.php文件应如下所示:
<?php
use Illuminate\Database\Seeder;
class LoginTableSeeder extends Seeder
{
public function run()
{
// your code goes here
}
}
you need to import Seeder
with use
at the beginning of file and again class name should start with capital letter.
你需要在文件的开头导入Seeder,并且类名应该以大写字母开头。
Now you should run composer dump-autoload
and now when you run php artisan db:seed
it will work fine.
现在你应该运行composer dump-autoload,现在当你运行php artisan db:seed它会正常工作。
#3
8
Just run composer dump-autoload -o
for the autoloader to pick up the newly classes because the database folder is not automatically autoloaded with PSR-4.
只需为自动加载器运行composer dump-autoload -o以获取新类,因为数据库文件夹不会自动使用PSR-4自动加载。
#4
2
This worked for me
这对我有用
composer dump-autoload -o
#5
1
I have the same problem but you can solve it by adding your namespace:
我有同样的问题,但你可以通过添加你的命名空间来解决它:
namespace yournamespace;
use App\Login;
use Illuminate\Database\Seeder;
#6
0
I've experienced the same problem. In my case, the composer was extremely old and after it's update everything runs Ok.
我遇到了同样的问题。在我的情况下,作曲家非常古老,在更新之后一切都运行正常。
Update composer with the command:
使用以下命令更新composer:
$ composer self-update
$ composer自我更新
Hope it can help others.
希望它可以帮助别人。