├── .github └── workflows │ └── test.yml ├── .gitignore ├── .php_cs ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── Models │ └── Revision.php └── Traits │ └── RevisionableUpgradeTrait.php └── tests ├── Models ├── BaseModel.php ├── Role.php ├── Seller.php └── User.php ├── RevisionableUpgradeTraitTest.php ├── ServiceProvider.php ├── TestCase.php └── database └── migrations ├── 2013_04_09_062329_create_revisions_table.php └── 2017_11_04_163552_create_database.php /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | php_version: [7.2] 15 | laravel_version: [5.5.*,6.*,7.*,8.*] 16 | 17 | steps: 18 | - name: Checkout commit 19 | uses: actions/checkout@v2 20 | 21 | - name: Setup PHP 22 | uses: shivammathur/setup-php@v1 23 | with: 24 | php-version: ${{ matrix.php_version }} 25 | 26 | - name: Validate composer.json 27 | run: composer validate 28 | 29 | - name: Run composer install 30 | run: composer install --no-interaction --no-suggest 31 | 32 | - name: Install Laravel 33 | run: composer update --no-interaction illuminate/database:^${{ matrix.laravel_version }} 34 | 35 | - name: Run PHPUnit 36 | run: ./vendor/bin/phpunit -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /.idea 3 | composer.lock 4 | .php_cs.cache 5 | .phpunit.result.cache -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in([ 11 | __DIR__ .'/src', 12 | __DIR__ .'/tests', 13 | ]); 14 | ; 15 | 16 | /* 17 | * Do the magic 18 | */ 19 | return Config::create() 20 | ->setUsingCache(false) 21 | ->setRules([ 22 | '@PSR2' => true, 23 | '@Symfony' => true, 24 | ]) 25 | ->setFinder($finder) 26 | ; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Filip Horvat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel revisionable upgrade 2 | 3 | Upgrade for the [Venturecraft Revisionable](https://github.com/VentureCraft/revisionable) package, many useful methods are added. 4 | 5 | ## Why to use 6 | 7 | Yeah, revisionable package has userResponsible () method, but that is not enough and we can use saved revisions for much more useful stuff. We can find out who created, deleted and edited model, when the model was edited, when exact attribute from the model was edited and much more. 8 | 9 | * You don't need to add **updated_by**, **deleted_by**, **created_by** to your tables. 10 | * You don't need to add **updated_attribute_by** to your tables. 11 | * You don't need to add **updated_attribute_to_value_by** to your tables. 12 | * You don't need to add **updated_attribute_from_value_to_value_by** to your tables. 13 | * You don't need to add **updated_attribute_at** to your tables. 14 | * You don't need to add **updated_attribute_to_value_at** to your tables. 15 | * You don't need to add **updated_attribute_from_value_to_value_at** to your tables. 16 | * You don't need **author_id**, **created_user_id**, **deleted_user_id** etc. or anything like that 17 | 18 | Don't pollute your tables with above table columns in the database, all above information is already stored in revisions table we just need the ability to get them, and this package will help you with that. 19 | 20 | ## Version Compatibility 21 | 22 | The package is available for larvel 5.* versions 23 | 24 | ## Install 25 | 26 | 1.Install package with composer 27 | ``` 28 | composer require fico7489/laravel-revisionable-upgrade:"*" 29 | ``` 30 | 31 | 2.Use Fico7489\Laravel\RevisionableUpgrade\Traits\RevisionableUpgradeTrait trait in your base model or only in particular models. Model which use RevisionableUpgradeTrait must also use RevisionableTrait; 32 | 33 | ``` 34 | ... 35 | use Venturecraft\Revisionable\RevisionableTrait; 36 | use Fico7489\Laravel\RevisionableUpgrade\Traits\RevisionableUpgradeTrait; 37 | 38 | abstract class BaseModel extends Model 39 | { 40 | use RevisionableTrait; 41 | use RevisionableUpgradeTrait; 42 | 43 | //enable this if you want use methods that gets information about creating 44 | protected $revisionCreationsEnabled = true; 45 | ... 46 | ``` 47 | 48 | and that's it, you are ready to go. 49 | 50 | ## New methods 51 | 52 | * **userCreated()** 53 | Returns user which created this model 54 | * **userDeleted()** 55 | Returns user which deleted this model 56 | * **userUpdated($key = null, $newValue = null, $oldValue = null)** 57 | Returns user which updated this model (last user if there are more) 58 | 59 | 60 | * **revisionCreated()** 61 | Returns revision for model created 62 | * **revisionDeleted()** 63 | Returns revision for model deleted 64 | * **revisionUpdated($key = null, $newValue = null, $oldValue = null)** 65 | Returns revision for model updated (last revision if there are more) 66 | 67 | 68 | * **dateUpdated($key = null, $newValue = null, $oldValue = null)** 69 | Returns date(Carbon\Carbon) for model updated (last revision if there are more) 70 | * **revisionsUpdated($key = null, $newValue = null, $oldValue = null)** 71 | Returns revisions for model updated 72 | * **usersUpdated($key = null, $newValue = null, $oldValue = null)** 73 | Returns users for model updated 74 | 75 | Clarification for methods with **($key = null, $newValue = null, $oldValue = null)** 76 | 77 | * All parameters are optional 78 | * If you provide $key method will look for changes on that key/field 79 | * If you provide $newValue method will look for changes where key/field is changed to this value 80 | * If you provide $oldValue method will look for changes where key/field is changed from this value 81 | 82 | We don't need **dateCreated** and **dateDeleted** because information about this is stored in created_at and deleted_at. 83 | We don't need **revisionsCreated**, **revisionsDeleted**, **usersCreated**, **usersDeleted** because model can be created or deleted only once. 84 | Methods which returns **user** and **users** are using model from **auth.model** configuration. 85 | 86 | ## See some action 87 | 88 | ``` 89 | $seller = Seller::create(['email' => 'test@test.com']); 90 | 91 | //get user who edited model 92 | $seller->userCreated(); 93 | 94 | //get user who deleted model 95 | $seller->userDeleted(); 96 | 97 | //get user who updated model 98 | $seller->userUpdated(); 99 | 100 | //get user who updated attribute name in model 101 | $seller->userUpdated('name'); 102 | 103 | //get user who updated attribute name value to 'new_name' 104 | $seller->userUpdated('name', 'new_name'); 105 | 106 | //get user who updated attribute name value to 'new_name' value from 'old_name' value 107 | $seller->userUpdated('name', 'new_name', 'old_name'); 108 | 109 | //get revision model for create 110 | $seller->revisionCreated(); 111 | 112 | //get revision model for delete 113 | $seller->revisionDeleted(); 114 | 115 | //get revision model for update 116 | $seller->revisionUpdated(); 117 | 118 | //get date for update 119 | $seller->dateUpdated(); 120 | 121 | //get revisions for update 122 | $seller->revisionsUpdated(); 123 | 124 | //get users for update 125 | $seller->usersUpdated(); 126 | ``` 127 | 128 | 129 | ## Improtant notes 130 | Models where you want use this package must use created_at timestamp 131 | 132 | If you want fetch users that have deleted models you must enable $revisionCreationsEnabled 133 | ``` 134 | protected $revisionCreationsEnabled = true; 135 | ``` 136 | [See more](https://github.com/VentureCraft/revisionable) 137 | 138 | 139 | License 140 | ---- 141 | 142 | MIT 143 | 144 | 145 | **Free Software, Hell Yeah!** 146 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fico7489/laravel-revisionable-upgrade", 3 | "description": "Upgrade for the venturecraft revisionable package, add many useful methods.", 4 | "keywords": [ 5 | "laravel revisionable upgrade", 6 | "laravel updated_by ", 7 | "laravel deleted_by", 8 | "laravel created_by", 9 | "laravel updated_at by key" 10 | ], 11 | "homepage": "https://github.com/fico7489/laravel-revisionable-upgrade", 12 | "support": { 13 | "issues": "https://github.com/fico7489/laravel-revisionable-upgrade/issues", 14 | "source": "https://github.com/fico7489/laravel-revisionable-upgrade" 15 | }, 16 | "license": "MIT", 17 | "authors": [ 18 | { 19 | "name": "Filip Horvat", 20 | "email": "filip.horvat@am2studio.hr", 21 | "homepage": "http://am2studio.hr", 22 | "role": "Developer" 23 | } 24 | ], 25 | "require": { 26 | "illuminate/database": "^5.5|^6.0|^7.0|^8.0", 27 | "venturecraft/revisionable": "1.*" 28 | }, 29 | "require-dev": { 30 | "orchestra/testbench": "*", 31 | "friendsofphp/php-cs-fixer" : "*" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Fico7489\\Laravel\\RevisionableUpgrade\\": "src" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "Fico7489\\Laravel\\RevisionableUpgrade\\Tests\\": "tests/" 41 | } 42 | }, 43 | "minimum-stability": "dev", 44 | "prefer-stable": true 45 | } -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ./tests/ 22 | 23 | 24 | 25 | 26 | 27 | ./src 28 | 29 | ./tests 30 | ./vendor 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Models/Revision.php: -------------------------------------------------------------------------------- 1 | belongsTo($model, 'user_id'); 13 | if ($this->classUseTrait($model, SoftDeletes::class)) { 14 | $relation = $relation->withTrashed(); 15 | } 16 | 17 | return $this->belongsTo($model, 'user_id'); 18 | } 19 | 20 | private function classUseTrait($model, $trait) 21 | { 22 | $traits = class_uses($model); 23 | 24 | return isset($traits[$trait]) ? true : false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Traits/RevisionableUpgradeTrait.php: -------------------------------------------------------------------------------- 1 | getCreateRevision(); 17 | 18 | return $revision ? $revision->revisionUser : null; 19 | } 20 | 21 | /** 22 | * Returns user which deleted this model. 23 | * 24 | * @return \Illuminate\Database\Eloquent\Model|null 25 | */ 26 | public function userDeleted() 27 | { 28 | $revision = $this->getDeletedRevision(); 29 | 30 | return $revision ? $revision->revisionUser : null; 31 | } 32 | 33 | /** 34 | * Returns user which updated this model (last user if there are more). 35 | * 36 | * @param string|null $key 37 | * @param string|null $newValue 38 | * @param string|null $oldValue 39 | * 40 | * @return \Illuminate\Database\Eloquent\Model|null 41 | */ 42 | public function userUpdated($key = null, $newValue = null, $oldValue = null) 43 | { 44 | $revision = $this->getUpdatedRevision($key, $newValue, $oldValue); 45 | 46 | return $revision ? $revision->revisionUser : null; 47 | } 48 | 49 | /** 50 | * Returns revision for model created. 51 | * 52 | * @return \Fico7489\Laravel\RevisionableUpgrade\Models\Revision|null 53 | */ 54 | public function revisionCreated() 55 | { 56 | return $this->getCreateRevision(); 57 | } 58 | 59 | /** 60 | * Returns revision for model deleted. 61 | * 62 | * @return \Fico7489\Laravel\RevisionableUpgrade\Models\Revision|null 63 | */ 64 | public function revisionDeleted() 65 | { 66 | return $this->getDeletedRevision(); 67 | } 68 | 69 | /** 70 | * Returns revision for model updated (last revision if there are more). 71 | * 72 | * @param string|null $key 73 | * @param string|null $newValue 74 | * @param string|null $oldValue 75 | * 76 | * @return \Fico7489\Laravel\RevisionableUpgrade\Models\Revision|null 77 | */ 78 | public function revisionUpdated($key = null, $newValue = null, $oldValue = null) 79 | { 80 | return $this->getUpdatedRevision($key, $newValue, $oldValue); 81 | } 82 | 83 | /** 84 | * Returns date for model updated (last revision if there are more). 85 | * 86 | * @param string|null $key 87 | * @param string|null $newValue 88 | * @param string|null $oldValue 89 | * 90 | * @return \Carbon\Carbon|string|null 91 | */ 92 | public function dateUpdated($key = null, $newValue = null, $oldValue = null) 93 | { 94 | $revision = $this->getUpdatedRevision($key, $newValue, $oldValue); 95 | 96 | return $revision ? $revision->created_at : null; 97 | } 98 | 99 | /** 100 | * Returns revisions for model updated. 101 | * 102 | * @param string|null $key 103 | * @param string|null $newValue 104 | * @param string|null $oldValue 105 | * 106 | * @return \Illuminate\Support\Collection 107 | */ 108 | public function revisionsUpdated($key = null, $newValue = null, $oldValue = null) 109 | { 110 | return $this->getUpdatedRevision($key, $newValue, $oldValue, false); 111 | } 112 | 113 | /** 114 | * Returns users for model updated. 115 | * 116 | * @param string|null $key 117 | * @param string|null $newValue 118 | * @param string|null $oldValue 119 | * 120 | * @return \Illuminate\Support\Collection 121 | */ 122 | public function usersUpdated($key = null, $newValue = null, $oldValue = null) 123 | { 124 | $revisions = $this->getUpdatedRevision($key, $newValue, $oldValue, false); 125 | $users = collect(); 126 | foreach ($revisions as $revision) { 127 | if ($revision->revisionUser) { 128 | $users->push($revision->revisionUser); 129 | } 130 | } 131 | 132 | return $users->unique(); 133 | } 134 | 135 | private function getCreateRevision() 136 | { 137 | $primaryKey = $this->primaryKey; 138 | 139 | return Revision::where([ 140 | 'revisionable_id' => $this->$primaryKey, 141 | 'revisionable_type' => $this->getMorphClass(), 142 | 'key' => 'created_at', 143 | 'old_value' => null, 144 | ])->first(); 145 | } 146 | 147 | private function getDeletedRevision() 148 | { 149 | $primaryKey = $this->primaryKey; 150 | 151 | return Revision::where([ 152 | 'revisionable_id' => $this->$primaryKey, 153 | 'revisionable_type' => $this->getMorphClass(), 154 | 'key' => 'deleted_at', 155 | 'old_value' => null, 156 | ])->first(); 157 | } 158 | 159 | private function getUpdatedRevision($key, $newValue, $oldValue, $first = true) 160 | { 161 | $primaryKey = $this->primaryKey; 162 | 163 | $revision = Revision::where([ 164 | 'revisionable_id' => $this->$primaryKey, 165 | 'revisionable_type' => $this->getMorphClass(), 166 | ])->where('key', '<>', 'created_at'); 167 | 168 | if (null !== $key) { 169 | $revision = $revision->where(['key' => $key]); 170 | } 171 | 172 | if (null !== $newValue) { 173 | $revision = $revision->where(['new_value' => $newValue]); 174 | } 175 | 176 | if (null !== $oldValue) { 177 | $revision = $revision->where(['old_value' => $oldValue]); 178 | } 179 | 180 | $revision = $revision->orderBy('created_at', 'desc')->orderBy('id', 'desc'); 181 | 182 | if ($first) { 183 | $revision = $revision->first(); 184 | } else { 185 | $revision = $revision->get(); 186 | } 187 | 188 | return $revision; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /tests/Models/BaseModel.php: -------------------------------------------------------------------------------- 1 | belongsToMany(User::class) 14 | ->withPivot(['value']); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Models/User.php: -------------------------------------------------------------------------------- 1 | belongsToMany(Role::class) 21 | ->withPivot(['value']); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/RevisionableUpgradeTraitTest.php: -------------------------------------------------------------------------------- 1 | 'example@example.com']); 14 | User::create(['name' => 'example2@example.com']); 15 | User::create(['name' => 'example3@example.com']); 16 | User::create(['name' => 'example4@example.com']); 17 | } 18 | 19 | public function test_userCreated() 20 | { 21 | $this->be(User::find(1)); 22 | $user = User::create(['name' => 'test']); 23 | $this->assertEquals(1, $user->userCreated()->id); 24 | 25 | $this->be(User::find(2)); 26 | $user = User::create(['name' => 'test']); 27 | $this->assertEquals(2, $user->userCreated()->id); 28 | 29 | $count = \DB::table('revisions')->count(); 30 | $this->be(User::find(2)); 31 | $user->update(['name' => 'test5']); 32 | $this->assertEquals(2, $user->userCreated()->id); 33 | 34 | $countNew = \DB::table('revisions')->count(); 35 | $this->assertEquals(($count + 1), $countNew); 36 | 37 | $this->be(User::find(2)); 38 | $user->update(['name' => 'test5']); 39 | $this->assertEquals(2, $user->userCreated()->id); 40 | } 41 | 42 | public function test_userDeleted() 43 | { 44 | $this->be(User::find(1)); 45 | $user = User::create(['name' => 'test']); 46 | $user->delete(); 47 | $this->assertEquals(1, $user->userDeleted()->id); 48 | 49 | $user = User::create(['name' => 'test']); 50 | $this->be(User::find(2)); 51 | $user->delete(); 52 | $this->assertEquals(2, $user->userDeleted()->id); 53 | } 54 | 55 | public function test_userUpdatedWithoutParams() 56 | { 57 | $this->be(User::find(1)); 58 | $user = User::create(['name' => 'test']); 59 | 60 | $this->be(User::find(2)); 61 | $user->update(['name' => 'test6', 'email' => 'test6']); 62 | $this->assertEquals(2, $user->userUpdated()->id); 63 | $this->assertEquals(2, $user->userUpdated('name')->id); 64 | 65 | $this->be(User::find(3)); 66 | $user->update(['name' => 'test7']); 67 | $this->assertEquals(3, $user->userUpdated()->id); 68 | $this->assertEquals(3, $user->userUpdated('name')->id); 69 | $this->assertEquals(2, $user->userUpdated('email')->id); 70 | 71 | $this->be(User::find(4)); 72 | $user->update(['name' => 'test8']); 73 | $this->assertEquals(2, $user->userUpdated('name', 'test6')->id); 74 | $this->assertEquals(3, $user->userUpdated('name', 'test7')->id); 75 | $this->assertEquals(3, $user->userUpdated('name', 'test7', 'test6')->id); 76 | 77 | $this->assertEquals(null, $user->userUpdated('namee')); 78 | $this->assertEquals(null, $user->userUpdated('name', 'test9')); 79 | $this->assertEquals(null, $user->userUpdated('name', 'test7', 'test9')); 80 | } 81 | 82 | public function test_dateUpdated() 83 | { 84 | $this->be(User::find(1)); 85 | $user = User::create(['name' => 'test']); 86 | $this->assertNull($user->dateUpdated()); 87 | 88 | $user->update(['name' => 'test2']); 89 | $this->assertNotNull($user->dateUpdated()); 90 | } 91 | 92 | public function test_revisionCreated() 93 | { 94 | $this->be(User::find(1)); 95 | $user = User::create(['name' => 'test']); 96 | $this->assertNotNull($user->revisionCreated()); 97 | } 98 | 99 | public function test_revisionDeleted() 100 | { 101 | $this->be(User::find(1)); 102 | $user = User::create(['name' => 'test']); 103 | $this->assertNull($user->revisionDeleted()); 104 | 105 | $user->delete(); 106 | $this->assertNotNull($user->revisionDeleted()); 107 | } 108 | 109 | public function test_revisionUpdated() 110 | { 111 | $this->be(User::find(1)); 112 | $user = User::create(['name' => 'test']); 113 | $this->assertNull($user->revisionUpdated()); 114 | 115 | $user->update(['name' => 'test2']); 116 | $this->assertNotNull($user->revisionUpdated()); 117 | } 118 | 119 | public function test_revisionsUpdated() 120 | { 121 | $this->be(User::find(2)); 122 | $user = User::create(['name' => 'test']); 123 | $this->assertEquals(0, $user->revisionsUpdated()->count()); 124 | 125 | $user->update(['name' => 'test2']); 126 | $this->assertEquals(1, $user->revisionsUpdated()->count()); 127 | 128 | $user->update(['name' => 'test3']); 129 | $this->assertEquals(2, $user->revisionsUpdated()->count()); 130 | } 131 | 132 | public function test_usersUpdated() 133 | { 134 | $this->be(User::find(2)); 135 | $user = User::create(['name' => 'test']); 136 | $this->assertEquals(0, $user->usersUpdated()->count()); 137 | 138 | $user->update(['name' => 'test2']); 139 | $this->assertEquals(1, $user->usersUpdated()->count()); 140 | $this->assertEquals(2, $user->usersUpdated()->first()->id); 141 | 142 | $user->update(['name' => 'test3']); 143 | $this->assertEquals(1, $user->usersUpdated()->count()); 144 | 145 | $this->be(User::find(3)); 146 | $user->update(['name' => 'test4']); 147 | $this->assertEquals(2, $user->usersUpdated()->count()); 148 | $this->assertEquals(3, $user->usersUpdated()->first()->id); 149 | $this->assertEquals(2, $user->usersUpdated()->last()->id); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /tests/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadMigrationsFrom(__DIR__.'/database/migrations/'); 15 | } 16 | 17 | protected function loadMigrationsFrom($path) 18 | { 19 | \Artisan::call('migrate', ['--database' => 'testbench']); 20 | $migrator = $this->app->make('migrator'); 21 | $migrator->run($path); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | set('auth.providers.users.model', \Fico7489\Laravel\RevisionableUpgrade\Tests\Models\User::class); 16 | $app['config']->set('database.default', 'testbench'); 17 | $app['config']->set('database.connections.testbench', [ 18 | 'driver' => 'sqlite', 19 | 'database' => ':memory:', 20 | 'prefix' => '', 21 | ]); 22 | } 23 | 24 | protected function getPackageProviders($app) 25 | { 26 | return [ServiceProvider::class]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/database/migrations/2013_04_09_062329_create_revisions_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 14 | $table->string('revisionable_type'); 15 | $table->integer('revisionable_id'); 16 | $table->integer('user_id')->nullable(); 17 | $table->string('key'); 18 | $table->text('old_value')->nullable(); 19 | $table->text('new_value')->nullable(); 20 | $table->timestamps(); 21 | 22 | $table->index(['revisionable_id', 'revisionable_type']); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down() 30 | { 31 | Schema::drop('revisions'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/database/migrations/2017_11_04_163552_create_database.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name'); 19 | 20 | $table->timestamps(); 21 | $table->softDeletes(); 22 | }); 23 | 24 | Schema::create('users', function (Blueprint $table) { 25 | $table->increments('id'); 26 | $table->string('name')->nullable(); 27 | $table->string('email')->nullable(); 28 | 29 | $table->timestamps(); 30 | $table->softDeletes(); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | */ 37 | public function down() 38 | { 39 | Schema::drop('users'); 40 | Schema::drop('sellers'); 41 | } 42 | } 43 | --------------------------------------------------------------------------------