Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainChannel->GroupChannel->Channel->Activities
- OnlineChannels->SocialMedia->Youtube->Activities
- OnlineChannels->SocialMedia->Facebook->Activities
- OnlineChannels->Webpages->Something.com->Activities
- OfflineChannels->Face-To-Face->Congress->Activities
- id | name | lft | rgt | depth | color | important_links | parent_id
- $GroupChannels = Channel::where('depth', 2)->with(
- 'parent',
- 'children',
- 'children.activities'
- );
- if(isset($input['filtered_channels'])){
- $Channels = $Channels->whereIn('id', $input['filtered_channels']);
- }
- $Channels = $Channels->get();
- foreach($GroupChannels as $Channel){
- foreach($Channel->children as $Subchannel){
- foreach ($Subchannel->activities as $Activity){
- $removeActivity = false;
- // do some checks on the activity that will maybe turn the $removeActivity to true
- if($removeActivity){
- $Subchannel->forget($Activity);
- }
- }
- //forget Subchannel if not Activities remain
- }
- //forget Channel if not Subchannels remain
- }
- class Channel extends Model
- {
- use CrudTrait;
- use SoftDeletes;
- use VenturecraftRevisionableRevisionableTrait;
- /*
- |--------------------------------------------------------------------------
- | GLOBAL VARIABLES
- |--------------------------------------------------------------------------
- */
- protected $table = 'channels';
- protected $primaryKey = 'id';
- protected $fillable = ['name', 'color', 'parent_id', 'lft', 'rgt', 'depth', 'important_links'];
- protected $dates = ['created_at', 'updated_at', 'deleted_at'];
- /*
- |--------------------------------------------------------------------------
- | FUNCTIONS
- |--------------------------------------------------------------------------
- */
- public static function boot()
- {
- parent::boot();
- }
- /*
- |--------------------------------------------------------------------------
- | RELATIONS
- |--------------------------------------------------------------------------
- */
- public function activities()
- {
- return $this->belongsToMany(Activity::class);
- }
- public function children()
- {
- return $this->hasMany(Channel::class, 'parent_id', 'id');
- }
- public function parent()
- {
- return $this->hasOne(Channel::class, 'id', 'parent_id');
- }
- /*
- |--------------------------------------------------------------------------
- | ACCESORS
- |--------------------------------------------------------------------------
- */
- public function getChildrenAttribute(){
- return $this->children()->orderBy('lft');
- }
- }
- HasMany {#872 ▼
- #foreignKey: "channels.parent_id"
- #localKey: "id"
- #query: Builder {#831 ▶}
- #parent: Channel {#840 ▶}
- #related: Channel {#832 ▶}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement