Files
backend/app/Models/SafetyAndPrivacy.php

85 lines
2.0 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',
];
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))
);
}
}