SmartCane/laravel_app/app/Models/ProjectDownload.php
2024-06-25 16:50:30 +02:00

42 lines
902 B
PHP

<?php
namespace App\Models;
use App\Events\ProjectDownloadStatus;
use App\Traits\HasStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
class ProjectDownload extends Model
{
use HasFactory;
use HasStatus;
protected $fillable = [
'name',
'path',
'status'
];
public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Project::class);
}
public function getDateAttribute():Carbon
{
return Carbon::parse(explode('.',$this->name)[0]);
}
protected static function booted(): void
{
parent::booted();
self::updated(function (ProjectDownload $projectDownload) {
event(new ProjectDownloadStatus($projectDownload));
});
}
}