Laravel SoftDelete magics - PullRequest
       5

Laravel SoftDelete magics

0 голосов
/ 26 апреля 2018

Я пытаюсь выяснить, почему restore из SoftDeletes объявлено как в Scope, так и в Trait:

SoftDeletingScope

protected function addRestore(Builder $builder)
{
    $builder->macro('restore', function (Builder $builder) {
        $builder->withTrashed();

        return $builder->update([$builder->getModel()->getDeletedAtColumn() => null]);
    });
}

черта SoftDeletes

public function restore()
{
    // If the restoring event does not return false, we will proceed with this
    // restore operation. Otherwise, we bail out so the developer will stop
    // the restore totally. We will clear the deleted timestamp and save.
    if ($this->fireModelEvent('restoring') === false) {
        return false;
    }

    $this->{$this->getDeletedAtColumn()} = null;

    // Once we have saved the model, we will fire the "restored" event so this
    // developer will do anything they need to after a restore operation is
    // totally finished. Then we will return the result of the save call.
    $this->exists = true;

    $result = $this->save();

    $this->fireModelEvent('restored', false);

    return $result;
}

Какая польза от первого и второго? Я пытаюсь создать свои собственные черты / возможности, основанные на использовании Laravel, но я просто не понимаю этого.

Если я правильно понимаю, что я читаю, оба делают одно и то же, за исключением того, что вызываемый из builder не вызывает события, а тот, что из модели, делает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...