public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            //Remove file from system
            if (file_exists($this->baseSource)) {
                unlink($this->baseSource);
            }

            //Delete from relation table
            if ($contentMedia = ContentMedia::find()->where(['media_id' => $this->id])->all()) {
                foreach ($contentMedia as $data) {
                    $data->delete();
                }
            }

            return true;
        }

        return false;
    }
public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            //Remove file from system
            if (file_exists($this->baseSource)) {
                unlink($this->baseSource);
            }

            //Delete from relation table
            if ($contentMedia = ContentMedia::find()->where(['media_id' => $this->id])->all()) {
                foreach ($contentMedia as $data) {
                    $data->delete();
                }
            }

            return true;
        }

        return false;
    }
public function beforeDelete ( ) { if ( parent :: beforeDelete ( ) ) { //Remove file from system if ( file_exists ( $ this -> baseSource ) ) { unlink ( $ this -> baseSource ) ; } //Delete from relation table if ( $ contentMedia = ContentMedia :: find ( ) -> where ( [ 'media_id' => $ this -> id ] ) -> all ( ) ) { foreach ( $ contentMedia as $ data ) { $ data -> delete ( ) ; } } return true ; } return false ; }
Before deletion, remove media file from source and also delete from relation table
@inheritdoc
Before deletion remove media file from source and also delete from relation table