Files
backend/app/Models/SafetyAndPrivacy.php
2025-08-13 13:41:34 +03:30

135 lines
3.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\SafetyAndPrivacyReportAble;
use Illuminate\Support\Facades\Storage;
class SafetyAndPrivacy extends Model
{
use SafetyAndPrivacyReportAble, HasFactory;
protected $fillable = [
'recognize_picture',
'lat',
'lon',
'operator_id',
'operator_name',
'province_id',
'province_fa',
'city_id',
'city_fa',
'info_id',
'info_fa',
'edare_shahri_id',
'edare_shahri_name',
'way_id',
'activity_date_time',
'step',
'step_fa',
'judiciary_document',
'judiciary_document_upload_date',
'action_picture',
'action_picture_document_upload_date',
'axis_type_id',
'axis_type_name',
'action_date',
'status',
'final_description',
'is_finished',
'supervisor_description',
'status_fa',
'need_judiciary',
'operator_description',
'supervisor_name',
'supervisor_id',
'finish_picture',
'evidence_picture',
'recognize_picture_2',
];
public $table = "safety_and_privacy";
public function goToFirstStep()
{
if($this->step == 0){
$this->step = 1;
$this->step_fa = 'گام اول (شناسایی)';
$this->save();
}
}
public function goToSecondStep()
{
if($this->step == 1){
$this->step = 2;
$this->step_fa = 'گام دوم (مستندات قضایی)';
$this->save();
}
}
public function goToThirdStep()
{
if($this->step == 2){
$this->step = 3;
$this->step_fa = 'گام سوم (برخورد)';
$this->save();
}
}
protected function recognizePicture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
protected function actionPicture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
protected function recognize_picture_2(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
protected function evidence_picture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
protected function finish_picture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
}