add autocounter

This commit is contained in:
nurmuhammet committed 2024-10-29 19:41:04 +05:00
1 parent 3eadd3c69b
commit efd49ae392
7 files changed
+38 -2

No files matched your search

@@ -23,7 +23,9 @@ public static function form(Form $form): Form
return $form
->schema([
TextInput::make('number')
->required(),
->integer()
->required()
->default(fn () => getLatestNumber() + 1),
TextInput::make('name')
->required(),
@@ -11,6 +11,6 @@ class CreateIncomingLetter extends CreateRecord
protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('index');
return $this->getResource()::getUrl('index');
}
}
+28
View File
@@ -3,7 +3,9 @@
use App\Modules\EmptyModule;
use App\Modules\ModuleContract;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
/**
@@ -94,3 +96,29 @@ function temp_cache(string $key = ''): mixed
? $tempCache->get($key)
: cache()->driver('array');
}
/**
* Log
*/
function logDB(): void
{
if (! app()->isLocal()) {
return;
}
DB::listen(function ($query) {
Log::info($query->sql, $query->bindings, $query->time);
});
}
/**
* Get latest number
*
* @param string $tableName
*/
function getLatestNumber(string $tableName = 'incoming_letters', string $column = 'number'): int
{
$data = DB::table($tableName)->select(DB::raw("MAX(CAST(REGEXP_REPLACE({$column}, '[^0-9]', '') AS UNSIGNED)) AS max_number"))->first();
return intval($data->max_number) ?? 0;
}
@@ -16,6 +16,7 @@ public function up(): void
$table->string('number')->nullable();
$table->string('name')->nullable();
$table->string('main_file')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
@@ -4,10 +4,12 @@
use App\Modules\Makeable;
use App\Modules\ModuleContract;
use Illuminate\Database\Eloquent\SoftDeletes;
class IncomingLetterModule implements ModuleContract
{
use Makeable;
use SoftDeletes;
/**
* Module is enabled
@@ -16,6 +16,7 @@ public function up(): void
$table->string('number')->nullable();
$table->string('name')->nullable();
$table->string('main_file')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
+2
View File
@@ -24,6 +24,8 @@ public function boot(): void
Model::shouldBeStrict(! app()->isProduction());
$this->registerModules();
// logDB();
}
/**