PHP code example of poluektov-software / laravel-relation-restore
1. Go to this page and download the library: Download poluektov-software/laravel-relation-restore library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
poluektov-software / laravel-relation-restore example snippets
//...
$table->integer( 'remove_code' )->nullable();
//...
//...
use Poluektov\RelationRestore\RelationRestore;
/**
* Class Model
*
* @package App\Models
*/
class Model
{
use RelationRestore;
//...
//...
protected $autoRemoveCode = 100;
//...
/**
* Model events handlers.
*
*/
public static function boot()
{
parent::boot();
static::deleting( function ( Model $model ) {
$model->relatedModels->each( function ( $relatedModel ) {
$relatedModel->autoRemove( $model->getAutoRemove() );
} );
} );
static::restoring( function ( Model $model ) {
$model->relatedModels()->onlyAutoRemoved( $model->getAutoRemove() )->each( function ( $relatedModel ) {
$relatedModel->autoRestore();
} );
} );
}
batch
$ php composer update
$ php composer