拉拉维尔没有找到雄辩的榜样

时间:2022-10-15 23:26:06

I'm brand new to Laravel and am having trouble loading my models in order to seed the database. I have tried both the Laravel 4 method of composer.json and the Laravel 5 PSR-4.

我是Laravel的新手,为了建立数据库,我在加载我的模型时遇到了麻烦。我已经试过了拉拉维尔四种作曲方法。json和Laravel 5 PSR-4。

DatabaseSeeder.php

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

}

Client.php

These are in app\Models at the moment, but I have tried them in app next to Users.php

这些目前都在app\模型中,但是我已经在user .php旁边的app中尝试过了

namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Client extends \Eloquent {
    proteced $fillable = ['id', 'name', 'email', 'created_at', 'updated_at'];
}

Module.php

namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Module extends \Eloquent {
    proteced $fillable = ['id', 'name', 'created_at', 'updated_at'];
}

ModuleConnection.php

namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;

class ModuleConnection extends \Eloquent {
    proteced $fillable = ['id', 'clientid', 'moduleid', 'apiconn', 'created_at', 'updated_at'];
}

The error

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!

我确信这是我作为一个初学者所缺少的愚蠢的东西!谢谢!

1 个解决方案

#1


1  

First, you probably have to extend Eloquent and not \Eloquent. When you add a \ on your usage, you are telling PHP to find an Eloquent in its root namespace. So:

首先,你可能需要有口才而不是口才。当您添加一个\的用法时,您是在告诉PHP在其根名称空间中找到一个合适的名称空间。所以:

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:

其次,没有必要做一个作曲家哑口无言,因为你的应用程序名称空间包含在Laravel安装中:

"autoload": {
    ...
    "psr-4": {
        "App\\": "app/"
    }
},

This is telling the autoloader to search for your namespaced classes in the app/ path.

这告诉autoloader在应用程序/路径中搜索命名空间类。

The thing you have to check is if the file Client.php is in the folder:

您需要检查的是文件客户端。php在文件夹中:

app/Models/Client.php

And named as is. Other than that I don't see a problem in your code.

和命名。除此之外,我在您的代码中没有看到任何问题。

#1


1  

First, you probably have to extend Eloquent and not \Eloquent. When you add a \ on your usage, you are telling PHP to find an Eloquent in its root namespace. So:

首先,你可能需要有口才而不是口才。当您添加一个\的用法时,您是在告诉PHP在其根名称空间中找到一个合适的名称空间。所以:

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:

其次,没有必要做一个作曲家哑口无言,因为你的应用程序名称空间包含在Laravel安装中:

"autoload": {
    ...
    "psr-4": {
        "App\\": "app/"
    }
},

This is telling the autoloader to search for your namespaced classes in the app/ path.

这告诉autoloader在应用程序/路径中搜索命名空间类。

The thing you have to check is if the file Client.php is in the folder:

您需要检查的是文件客户端。php在文件夹中:

app/Models/Client.php

And named as is. Other than that I don't see a problem in your code.

和命名。除此之外,我在您的代码中没有看到任何问题。