Laravel 5 Laravel雄辩的关系FatalErrorException在compiled.php行9573中:找不到课堂讲课
我试图在项目和讲座之间建立一对多的关系,讲座有很多项目 这是我的Laravel 5 Laravel雄辩的关系FatalErrorException在compiled.php行9573中:找不到课堂讲课,laravel-5,Laravel 5,我试图在项目和讲座之间建立一对多的关系,讲座有很多项目 这是我的讲座迁移表: Schema::create('lectures', function(Blueprint $table) { $table->increments('id'); $table->string('title', 255); $table->integer('lecturer'); });
讲座
迁移表:
Schema::create('lectures', function(Blueprint $table) {
$table->increments('id');
$table->string('title', 255);
$table->integer('lecturer');
});
Schema::create('items', function(Blueprint $table) {
$table->increments('id');
$table->string('name', 255);
$table->integer('lecture_id');
$table->foreign('lecture_id')->references('id')
->on('lectures');
});
这是我的项目
迁移表:
Schema::create('lectures', function(Blueprint $table) {
$table->increments('id');
$table->string('title', 255);
$table->integer('lecturer');
});
Schema::create('items', function(Blueprint $table) {
$table->increments('id');
$table->string('name', 255);
$table->integer('lecture_id');
$table->foreign('lecture_id')->references('id')
->on('lectures');
});
最后,以下是我如何将它们连接在一起:
class Item extends Model
{
public function lecture()
{
return $this->belongsTo('Lecture', 'lecture_id', 'id');
}
}
及
我想知道出了什么问题,为什么我总是出错。我尝试了
composer dump autoload
,php-artisan-migrate:refresh
,以及php-artisan-db:seed
。但在Laravel 5中,它不起作用,在使用其他类时,需要在代码中添加“use”行
如果你的课堂模型课就在应用程序目录下,你需要添加
use App\Lecture;
您的PHP代码/类需要它。谢谢,虽然这并不完全正确,但我发现错误是因为我没有使用完整路径。我应该写
return$this->belongsTo('App\Models\AMS1B\touch','touch\u id','id')代码>而不仅仅是讲座