Laravel查询“仅当”条件

  1. 用户(用户/组织/小组)作为创建者有很多故事。
  2. 故事包含故事的许多部分。
  3. 用户(用户/组织/组)具有订阅者(另一个
  4. 用户/组织/组)。
  5. 故事的一部分可能是私人的。

仅当auth()-> user()(用户/组织/组)是故事创建者(另一个用户/组织/组)的订户时,才如何选择所有部分都具有private == false和private == true的故事。

//Stories table
create table stories
(
    id           bigint unsigned auto_increment primary key,
    creator_id   int unsigned                   not null,
    creator_type varchar(255)                   not null,
    created_at   timestamp                      null,
    updated_at   timestamp                      null
)

//Stories parts table
create table stories_parts
(
    id             bigint unsigned auto_increment          primary key,
    story_id       int                                     not null,
    private        tinyint
    created_at     timestamp                               null,
    updated_at     timestamp                               null
)

//User has subscribers (Another User/Organization/Group)
create table user_subscribers
(
    user_id         bigint unsigned not null,
    subscriber_id   bigint unsigned not null,
    subscriber_type varchar(255)    not null
)

//Organization has subscribers (Another User/Organization/Group)
create table organization_subscribers
(
    organization_id bigint unsigned not null,
    subscriber_id   bigint unsigned not null,
    subscriber_type varchar(255)    not null
)

//Group has subscribers (Another User/Organization/Group)
create table group_subscribers
(
    organization_id bigint unsigned not null,
    subscriber_id   bigint unsigned not null,
    subscriber_type varchar(255)    not null
)
评论