for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Sausin\DBSetAutoIncrement;
use Illuminate\Support\Facades\DB;
trait UpdateAttribute
{
/**
* @param string $driver
*/
protected function updateAutoIncrement($driver, $table): void
$method = "update{$driver}AutoIncrement";
// perform changes as a transaction to avoid
// borking the database in case of issues.
DB::transaction(function () use ($method, $table) {
$this->{$method}($table);
});
}
protected function updateMysqlAutoIncrement($table): void
DB::statement("ALTER TABLE {$table} AUTO_INCREMENT={$this->autoIncrement}");
autoIncrement
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
protected function updateSqliteAutoIncrement($table): void
DB::statement("DELETE FROM SQLITE_SEQUENCE WHERE name = '{$table}'");
DB::statement("INSERT INTO SQLITE_SEQUENCE(name, seq) VALUES('{$table}', {$this->autoIncrement})");
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: