add autocounter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user