You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
2.0 KiB

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OverSpeedRed extends Model
{
use HasFactory;
protected $table = 'overspeedred';
protected $primaryKey = 'id';
protected $fillable = [
'picture',
'picture2',
'serialnumber',
'location',
'limitspeed',
'violationtype',
'violationcode',
'cartype',
'sid',
'datatime',
'speed',
'carnumber',
'processcheck',
'jsoncheck',
'unreportreason',
'unreportpicture',
'unreportmergedone'
];
protected $appends = [
'law_type',
];
public function violationlaw()
{
return $this->hasOne(ViolationLaw::class, 'violationcode', 'violationcode');
}
public function getLawTypeAttribute()
{
// 取得陣列
$violationtype = $this->violationtype;
// $violationtype = [];
if ($violationtype == "未依標誌標線號誌" || $violationtype == "未依標誌標線行駛") {
$violationtype = ["未依標誌標線號誌行駛"];
} else if ($violationtype == "闖紅燈") {
$violationtype = ["闖紅燈", "紅燈右轉", "紅燈越線"];
} else if ($violationtype == "未禮讓行人") {
$violationtype = ["未禮讓行人"];
} else if ($violationtype == "違規停車") {
$violationtype = ["違規停車"];
} else if ($violationtype == "未保持路口淨空") {
$violationtype = ["未保持路口淨空"];
} else if ($violationtype == "超速") {
$violationtype = ["超速"];
} else {
$violationtype = [$violationtype];
}
$types = ViolationLaw::whereIn('type', $violationtype)->get();
$lawData = [];
foreach ($types as $type) {
$lawData["$type->violationcode"] = "[$type->violationcode] $type->display_name";
}
return $lawData;
}
}