original_string: public function markAsRead($type = 'notifications')
      {
          DB::beginTransaction();
          try {
              $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications();
              $read    = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id');
              $items   = $builder->whereNotIn('id', $read)->get();
  
              foreach ($items as $item) {
                  $item->read()->save(new NotificationsStackRead([
                      'user_id' => user()->id
                  ]));
                  $item->save();
              }
          } catch (Exception $ex) {
              DB::rollback();
              return false;
          }
          return DB::commit();
      }
code: public function markAsRead($type = 'notifications')
      {
          DB::beginTransaction();
          try {
              $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications();
              $read    = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id');
              $items   = $builder->whereNotIn('id', $read)->get();
  
              foreach ($items as $item) {
                  $item->read()->save(new NotificationsStackRead([
                      'user_id' => user()->id
                  ]));
                  $item->save();
              }
          } catch (Exception $ex) {
              DB::rollback();
              return false;
          }
          return DB::commit();
      }
code_tokens: public function markAsRead ( $ type = 'notifications' ) { DB :: beginTransaction ( ) ; try { $ builder = ( $ type === 'alerts' ) ? $ this -> getAlerts ( ) : $ this -> getNotifications ( ) ; $ read = NotificationsStackRead :: select ( [ 'stack_id' ] ) -> withTrashed ( ) -> where ( 'user_id' , user ( ) -> id ) -> pluck ( 'stack_id' ) ; $ items = $ builder -> whereNotIn ( 'id' , $ read ) -> get ( ) ; foreach ( $ items as $ item ) { $ item -> read ( ) -> save ( new NotificationsStackRead ( [ 'user_id' => user ( ) -> id ] ) ) ; $ item -> save ( ) ; } } catch ( Exception $ ex ) { DB :: rollback ( ) ; return false ; } return DB :: commit ( ) ; }
docstring: Mark notifications or alerts as read
  
  @param String $type
  @return boolean
docstring_tokens: Mark notifications or alerts as read