国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

One-to-many problem in laravel
高洛峰
高洛峰 2017-05-16 16:48:52
0
1
375

I now have two tables:

One is the association list (list) and the user table (user)

List table fields

list_id(協(xié)會(huì)id) , list_name(協(xié)會(huì)名稱)

user user table

user_id(用戶id),list_id(所屬協(xié)會(huì)), username(用戶名)

How to achieve this:

Related query to obtain the total number of members under each association

For example:

{"list_name":"AAA協(xié)會(huì)","user_count":20},
{"list_name":"BBB協(xié)會(huì)","user_count":211}
...

How to connect?

高洛峰
高洛峰

擁有18年軟件開發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...

reply all(1)
大家講道理
class List extends Model
{
    protected $fillable = ['name'];

    public function users()
    {
        return $this->hasMany(User::class, 'list_id', 'id');
    }
}

class User extends Model
{
    protected $fillable = ['list_id'];

    public function list()
    {
        return $this->belongsTo(List::class, "list_id", "id");
    }
}

List::withCount("users")->paginate();

Read more documentation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template