- Users(User/Organization/Group) has many stories as creator.
- Stories has many parts of stories.
- Users(User/Organization/Group) has subscribers (Another User/Organization/Group).
- Part of stories may be private.
How select all stories where has parts where private == false and private == true only if auth()->user() (User/Organization/Group) is subscriber of story creator (Another User/Organization/Group).
//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 subscriptions (Another User/Organization/Group)
create table user_subscriptions
(
user_id bigint unsigned not null,
subscription_id bigint unsigned not null,
subscription_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
)
privatecomes from?->whereHas('parts', function($query){$query->where('private', false)})and i need where private == true if auth user is subscriber of creator