Now generating new link IDs at random
This commit is contained in:
parent
6f6502095f
commit
712101c3f4
|
@ -5,11 +5,29 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
|
||||||
class Link extends Model
|
class Link extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = ['link', 'title', 'button_id', 'type_params', 'typename'];
|
protected $fillable = ['link', 'title', 'button_id', 'type_params', 'typename'];
|
||||||
|
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($link) {
|
||||||
|
if (config('linkstack.disable_random_link_ids') != 'true') {
|
||||||
|
$numberOfDigits = config('linkstack.link_id_length') ?? 9;
|
||||||
|
|
||||||
|
$minIdValue = 10**($numberOfDigits - 1);
|
||||||
|
$maxIdValue = 10**$numberOfDigits - 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$randomId = rand($minIdValue, $maxIdValue);
|
||||||
|
} while (Link::find($randomId));
|
||||||
|
|
||||||
|
$link->id = $randomId;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue