Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. MainChannel->GroupChannel->Channel->Activities
  2.  
  3. OnlineChannels->SocialMedia->Youtube->Activities
  4. OnlineChannels->SocialMedia->Facebook->Activities
  5. OnlineChannels->Webpages->Something.com->Activities
  6. OfflineChannels->Face-To-Face->Congress->Activities
  7.  
  8. id | name | lft | rgt | depth | color | important_links | parent_id
  9.  
  10. $GroupChannels = Channel::where('depth', 2)->with(
  11. 'parent',
  12. 'children',
  13. 'children.activities'
  14. );
  15.  
  16. if(isset($input['filtered_channels'])){
  17. $Channels = $Channels->whereIn('id', $input['filtered_channels']);
  18. }
  19. $Channels = $Channels->get();
  20.  
  21. foreach($GroupChannels as $Channel){
  22. foreach($Channel->children as $Subchannel){
  23. foreach ($Subchannel->activities as $Activity){
  24. $removeActivity = false;
  25. // do some checks on the activity that will maybe turn the $removeActivity to true
  26. if($removeActivity){
  27. $Subchannel->forget($Activity);
  28. }
  29. }
  30. //forget Subchannel if not Activities remain
  31. }
  32. //forget Channel if not Subchannels remain
  33. }
  34.  
  35. class Channel extends Model
  36. {
  37. use CrudTrait;
  38. use SoftDeletes;
  39. use VenturecraftRevisionableRevisionableTrait;
  40. /*
  41. |--------------------------------------------------------------------------
  42. | GLOBAL VARIABLES
  43. |--------------------------------------------------------------------------
  44. */
  45.  
  46. protected $table = 'channels';
  47. protected $primaryKey = 'id';
  48. protected $fillable = ['name', 'color', 'parent_id', 'lft', 'rgt', 'depth', 'important_links'];
  49. protected $dates = ['created_at', 'updated_at', 'deleted_at'];
  50.  
  51. /*
  52. |--------------------------------------------------------------------------
  53. | FUNCTIONS
  54. |--------------------------------------------------------------------------
  55. */
  56. public static function boot()
  57. {
  58. parent::boot();
  59. }
  60. /*
  61. |--------------------------------------------------------------------------
  62. | RELATIONS
  63. |--------------------------------------------------------------------------
  64. */
  65. public function activities()
  66. {
  67. return $this->belongsToMany(Activity::class);
  68. }
  69. public function children()
  70. {
  71. return $this->hasMany(Channel::class, 'parent_id', 'id');
  72. }
  73. public function parent()
  74. {
  75. return $this->hasOne(Channel::class, 'id', 'parent_id');
  76. }
  77.  
  78. /*
  79. |--------------------------------------------------------------------------
  80. | ACCESORS
  81. |--------------------------------------------------------------------------
  82. */
  83. public function getChildrenAttribute(){
  84. return $this->children()->orderBy('lft');
  85. }
  86. }
  87.  
  88. HasMany {#872 ▼
  89. #foreignKey: "channels.parent_id"
  90. #localKey: "id"
  91. #query: Builder {#831 ▶}
  92. #parent: Channel {#840 ▶}
  93. #related: Channel {#832 ▶}
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement