ldc-qrcollector-back/app/Models/UrlStats.php
2026-02-12 16:09:21 +01:00

54 lines
1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UrlStats extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'calls',
'date',
'url_id',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'date' => 'date',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model) {
$model->calls = 1;
$model->date = now();
});
}
/**
* Get the url that owns the stats.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Url, $this>
*/
public function url()
{
return $this->belongsTo(Url::class);
}
}