29 lines
661 B
PHP
29 lines
661 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Bobot extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $primaryKey = 'bobotId';
|
|
protected $keyType = 'string';
|
|
protected $fillable = [
|
|
'bobotId',
|
|
'bobot',
|
|
'nilai',
|
|
];
|
|
|
|
public function generateId()
|
|
{
|
|
$maxId = DB::table('bobots')->max(DB::raw('CAST(SUBSTRING(bobotId, 6) AS UNSIGNED)'));
|
|
$maxId = $maxId ? : 0;
|
|
$newId = $maxId + 1;
|
|
$formattedId = sprintf("%02d", $newId);
|
|
return 'BBID-' . $formattedId;
|
|
}
|
|
}
|