34 lines
641 B
PHP
34 lines
641 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class BioSpecimen extends Model
|
|
{
|
|
protected $table = 'bio_specimens';
|
|
protected $guarded = [];
|
|
|
|
protected $appends = ['storage_days'];
|
|
|
|
public function cabinet()
|
|
{
|
|
return $this->belongsTo(BioCabinet::class, 'cabinet_id');
|
|
}
|
|
|
|
public function rack()
|
|
{
|
|
return $this->belongsTo(BioRack::class, 'rack_id');
|
|
}
|
|
|
|
public function getStorageDaysAttribute()
|
|
{
|
|
if (!$this->stored_at) {
|
|
return 0;
|
|
}
|
|
|
|
return Carbon::parse($this->stored_at)->diffInDays(Carbon::now());
|
|
}
|
|
}
|