'int', 'view_position' => 'int', 'booking_id' => 'int', 'type_id' => 'int', 'in_pdf' => 'bool', 'state' => 'datetime', 'begin' => 'datetime', 'end' => 'datetime', ]; protected $fillable = [ 'template_id', 'state', 'begin', 'end', 'type_s', 'data_s', 'view_position', 'booking_id', 'type_id', 'in_pdf' ]; public function booking() { return $this->belongsTo(Booking::class); } public function arrangement_template() { return $this->belongsTo(ArrangementTemplate::class, 'template_id'); } public function arrangement_type() { return $this->belongsTo(ArrangementType::class, 'type_id'); } public function getDataAsMap() { $rawData = $this->attributes['data_s']; $data = json_decode('{'. $rawData .'}', true); if (is_array($data)) { return $data; } $entries = preg_split("/[\r\n;]+\s*/", $rawData, -1, PREG_SPLIT_NO_EMPTY); $ret = array(); foreach ($entries as $entry) { $map = preg_split('/:\s*/', $entry, -1, PREG_SPLIT_NO_EMPTY); if (count($map) == 2) { $ret[$map[0]] = $map[1]; } } return $ret; } public function getDataS() { $rawData = $this->attributes['data_s']; $data = json_decode('{'. $rawData .'}', true); if (is_array($data)) { $str = ''; $i = 0; foreach ($data as $k => $v) { if (++$i > 0) { $str .= ''; } $str .= $k .' '. $v; } return $str; } return $rawData; } }