src/Repository/StackRepository.php
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();
    }
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();
    }
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 ( ) ; }
Mark notifications or alerts as read

@param String $type
@return boolean
Mark notifications or alerts as read