original_string: public function query()
      {
          $read = NotificationsStackRead::select(['stack_id'])
                  ->withTrashed()
                  ->where('user_id', user()->id)
                  ->whereNotNull('deleted_at')
                  ->pluck('stack_id');
          return $this->makeModel()->newQuery()
                          ->distinct()
                          ->select(['tbl_notifications_stack.*'])
                          ->whereHas('content', function($query) {
                              $query->where([
                                  'lang_id' => lang_id()
                              ]);
                          })
                          ->whereHas('notification', function($query) {
                              $query->whereHas('type', function($subquery) {
                                  $subquery->where('name', area());
                              });
                          })
                          ->where(function ($query) {
                              $query
                              ->whereNull('author_id')
                              ->orWhere('author_id', user()->id)
                              ->orWhereHas('author', function($subquery) {
                                  $subquery->whereHas('roles', function($rolesQuery) {
                                      $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds());
                                  });
                              })
                              ->orWhereHas('params', function($subquery) {
                                  $subquery->where('model_id', user()->id);
                              });
                          })
                          ->whereNotIn('id', $read)
                          ->with('author')
                          ->with('content')->with('notification.severity')
                          ->orderBy('tbl_notifications_stack.created_at', 'desc');
      }
code: public function query()
      {
          $read = NotificationsStackRead::select(['stack_id'])
                  ->withTrashed()
                  ->where('user_id', user()->id)
                  ->whereNotNull('deleted_at')
                  ->pluck('stack_id');
          return $this->makeModel()->newQuery()
                          ->distinct()
                          ->select(['tbl_notifications_stack.*'])
                          ->whereHas('content', function($query) {
                              $query->where([
                                  'lang_id' => lang_id()
                              ]);
                          })
                          ->whereHas('notification', function($query) {
                              $query->whereHas('type', function($subquery) {
                                  $subquery->where('name', area());
                              });
                          })
                          ->where(function ($query) {
                              $query
                              ->whereNull('author_id')
                              ->orWhere('author_id', user()->id)
                              ->orWhereHas('author', function($subquery) {
                                  $subquery->whereHas('roles', function($rolesQuery) {
                                      $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds());
                                  });
                              })
                              ->orWhereHas('params', function($subquery) {
                                  $subquery->where('model_id', user()->id);
                              });
                          })
                          ->whereNotIn('id', $read)
                          ->with('author')
                          ->with('content')->with('notification.severity')
                          ->orderBy('tbl_notifications_stack.created_at', 'desc');
      }
code_tokens: public function query ( ) { $ read = NotificationsStackRead :: select ( [ 'stack_id' ] ) -> withTrashed ( ) -> where ( 'user_id' , user ( ) -> id ) -> whereNotNull ( 'deleted_at' ) -> pluck ( 'stack_id' ) ; return $ this -> makeModel ( ) -> newQuery ( ) -> distinct ( ) -> select ( [ 'tbl_notifications_stack.*' ] ) -> whereHas ( 'content' , function ( $ query ) { $ query -> where ( [ 'lang_id' => lang_id ( ) ] ) ; } ) -> whereHas ( 'notification' , function ( $ query ) { $ query -> whereHas ( 'type' , function ( $ subquery ) { $ subquery -> where ( 'name' , area ( ) ) ; } ) ; } ) -> where ( function ( $ query ) { $ query -> whereNull ( 'author_id' ) -> orWhere ( 'author_id' , user ( ) -> id ) -> orWhereHas ( 'author' , function ( $ subquery ) { $ subquery -> whereHas ( 'roles' , function ( $ rolesQuery ) { $ rolesQuery -> whereIn ( 'tbl_roles.id' , user ( ) -> roles -> first ( ) -> getChilds ( ) ) ; } ) ; } ) -> orWhereHas ( 'params' , function ( $ subquery ) { $ subquery -> where ( 'model_id' , user ( ) -> id ) ; } ) ; } ) -> whereNotIn ( 'id' , $ read ) -> with ( 'author' ) -> with ( 'content' ) -> with ( 'notification.severity' ) -> orderBy ( 'tbl_notifications_stack.created_at' , 'desc' ) ; }
docstring: Gets base query builder for notifications and alerts
  
  @return \Illuminate\Database\Query\Builder
docstring_tokens: Gets base query builder for notifications and alerts