src/Eloquent/Repository.php
public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName)
    {
        // Validate model is soft deletable
        if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
            throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
        }

        // Retrieve all records by entity type and entity ID
        $entities = $this->onlyTrashed()
                         ->getBuilder()
                         ->select(['id'])
                         ->where(function ($query) use ($entity, $relationName) {
                             $query->where($relationName.'_type', '=', get_class($entity))
                                  ->where($relationName.'_id', '=', (int) $entity->id);
                         })
                         ->get();

        // Restore count
        $restoreCount = 0;

        // Loop through each entity individually.
        // This is required to soft delete all found entiries.
        foreach ($entities as $e) {
            if ((bool) $e->restore()) {
                $restoreCount += 1;
            }
        }

        // Reset query builder
        $this->resetBuilder();

        return $restoreCount;
    }
public function restoreMorphsByEntity(IlluminateEloquentModel $entity, $relationName)
    {
        // Validate model is soft deletable
        if (! in_array(IlluminateEloquentSoftDeletes::class, class_uses($this->getModel()))) {
            throw new ModelNotSoftDeletable('Model [%s] is not using the Soft Delete trait');
        }

        // Retrieve all records by entity type and entity ID
        $entities = $this->onlyTrashed()
                         ->getBuilder()
                         ->select(['id'])
                         ->where(function ($query) use ($entity, $relationName) {
                             $query->where($relationName.'_type', '=', get_class($entity))
                                  ->where($relationName.'_id', '=', (int) $entity->id);
                         })
                         ->get();

        // Restore count
        $restoreCount = 0;

        // Loop through each entity individually.
        // This is required to soft delete all found entiries.
        foreach ($entities as $e) {
            if ((bool) $e->restore()) {
                $restoreCount += 1;
            }
        }

        // Reset query builder
        $this->resetBuilder();

        return $restoreCount;
    }
public function restoreMorphsByEntity ( IlluminateEloquentModel $ entity , $ relationName ) { // Validate model is soft deletable if ( ! in_array ( IlluminateEloquentSoftDeletes :: class , class_uses ( $ this -> getModel ( ) ) ) ) { throw new ModelNotSoftDeletable ( 'Model [%s] is not using the Soft Delete trait' ) ; } // Retrieve all records by entity type and entity ID $ entities = $ this -> onlyTrashed ( ) -> getBuilder ( ) -> select ( [ 'id' ] ) -> where ( function ( $ query ) use ( $ entity , $ relationName ) { $ query -> where ( $ relationName . '_type' , '=' , get_class ( $ entity ) ) -> where ( $ relationName . '_id' , '=' , ( int ) $ entity -> id ) ; } ) -> get ( ) ; // Restore count $ restoreCount = 0 ; // Loop through each entity individually. // This is required to soft delete all found entiries. foreach ( $ entities as $ e ) { if ( ( bool ) $ e -> restore ( ) ) { $ restoreCount += 1 ; } } // Reset query builder $ this -> resetBuilder ( ) ; return $ restoreCount ; }
Restore morphed relations by entity.

Note: This should only be used with morphed relations

@author Morten Rugaard <moru@nodes.dk>

@param  \Illuminate\Database\Eloquent\Model $entity
@param  string                              $relationName
@return int
@throws \Nodes\Database\Exceptions\ModelNotSoftDeletable
Restore morphed relations by entity .