我有很多关系,从Page
到User
:
class User extends Model {
...
public function visits() {
return $this->belongsToMany('App\Page')->withTimestamps();
}
...
}
class Page extends Model {
...
public function visitedBy() {
return $this->belongsToMany('App\User')->withTimestamps();
}
...
}
使用以下数据透视表:
Schema::create('page_user', function(Blueprint $table)
{
$table->increments('id');
$table->integer('page_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->timestamps();
$table->foreign('page_id')
->references('id')
->on('pages')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
});
如何选择K
最近的网页访问次数,其中K
是已知的正整数?