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.
70 lines
2.1 KiB
70 lines
2.1 KiB
<?php |
|
|
|
namespace App\Models; |
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
class Multisys extends Model |
|
{ |
|
use HasFactory; |
|
protected $table = 'multisys'; |
|
|
|
protected $fillable = [ |
|
'picture', |
|
'picture2', |
|
'datatime', |
|
'cartype', |
|
'carnumber', |
|
'serialnumber', |
|
'location', |
|
'limitspeed', |
|
'speed', |
|
'sid', |
|
'violationtype', |
|
'violationcode', |
|
'processcheck', |
|
'postcheck', |
|
'jsoncheck', |
|
'unreportreason', |
|
'unreportpicture', |
|
'unreportmergedone', |
|
]; |
|
|
|
// append fields |
|
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 == "機車未依規定兩段式左轉") { |
|
$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; |
|
} |
|
}
|
|
|