[英]Laravel 5 Not Finding Eloquent Models
I'm brand new to Laravel and am having trouble loading my models in order to seed the database. 我是Laravel的新手,我无法加载我的模型以便为数据库播种。 I have tried both the Laravel 4 method of composer.json and the Laravel 5 PSR-4.
我尝试过composer.json的Laravel 4方法和Laravel 5 PSR-4。
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
\App\Models\Client::truncate();
\App\Models\Module::truncate();
\App\Models\ModuleConnection::truncate();
Model::unguard();
$this->call('ClientsTableSeeder');
$this->call('ModulesTableSeeder');
$this->call('ConncetionsTableSeeder');
}
}
These are in app\\Models at the moment, but I have tried them in app next to Users.php 这些都在app \\ Models中,但我在Apps.php旁边的应用程序中尝试过它们
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Client extends \Eloquent {
proteced $fillable = ['id', 'name', 'email', 'created_at', 'updated_at'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Module extends \Eloquent {
proteced $fillable = ['id', 'name', 'created_at', 'updated_at'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class ModuleConnection extends \Eloquent {
proteced $fillable = ['id', 'clientid', 'moduleid', 'apiconn', 'created_at', 'updated_at'];
}
This is when I run php artisan db:seed 这是我运行php artisan db:seed的时候
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'App\Models\Client' not found
I'm sure it's something stupid I'm missing as a beginner! 我确定这是一个愚蠢的东西,我作为一个初学者失踪了! Thanks!
谢谢!
First, you probably have to extend Eloquent and not \\Eloquent. 首先,你可能需要扩展Eloquent而不是\\ Eloquent。 When you add a \\ on your usage, you are telling PHP to find an Eloquent in its root namespace.
当您在使用中添加\\时,您告诉PHP在其根命名空间中找到Eloquent。 So:
所以:
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Module extends Eloquent {
proteced $fillable = ['id', 'name', 'created_at', 'updated_at'];
}
Second, there's no need to do a composer dumpautoload
because your App namespace was included by your Laravel instalation: 其次,没有必要进行
composer dumpautoload
因为你的应用程序命名空间包含在你的Laravel安装程序中:
"autoload": {
...
"psr-4": {
"App\\": "app/"
}
},
This is telling the autoloader to search for your namespaced classes in the app/
path. 这告诉自动加载器在
app/
path中搜索命名空间类。
The thing you have to check is if the file Client.php is in the folder: 您必须检查的是文件Client.php是否在文件夹中:
app/Models/Client.php
And named as is. 并命名为。 Other than that I don't see a problem in your code.
除此之外,我没有在您的代码中看到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.