2021-04-16 01:00:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Link extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2024-06-20 12:24:54 +02:00
|
|
|
protected $fillable = ['link', 'title', 'button_id', 'type_params', 'type'];
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2023-12-01 16:19:51 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|