class Course extends Model
{
protected $table = 'courses';
public function subscriptions()
{
return $this->belongsToMany(Subscription::class);
}
public function lessons()
{
return $this->hasMany(Lesson::class);
}
}
更新用户模型
class User extends Model
{
protected $table = 'users';
public function client()
{
return $this->belongsTo(Client::class);
}
public function lessons()
{
return $this->belongsToMany(Lesson::class)->withPivot('result');
}
}
php artisan make:model订阅
class Subscription extends Model
{
protected $table = 'subscriptions';
public function client()
{
return $this->belongsTo(Client::class);
}
public function courses()
{
return $this->belongsToMany(Course::class);
}
}
class Client extends Model
{
protected $table = 'clients';
public function subscriptions()
{
return $this->hasMany(Subscription::class);
}
public function users()
{
return $this->hasMany(User::class);
}
}
php artisan make:model客户端
class Lesson extends Model
{
protected $table = 'lessons';
public function courses()
{
return $this->belongsToMany(Course::class);
}
public function users()
{
return $this->belongsToMany(User::class)->withPivot('result');
}
}
1条答案
按热度按时间xwbd5t1u1#
这里是源代码,它是在一些假设的基础上构建的。因为很难假设所有相关的表和它的内容。
php artisan make:model课程
更新用户模型
php artisan make:model订阅
php artisan make:model客户端
web.php
这是您在CourseController控制器中编写的最后一个查询。
希望这对你有帮助。