fix view to array for education and experience calon

This commit is contained in:
nurafrinaalimi16
2024-04-28 11:48:23 +08:00
parent 194f28d584
commit aff14b29cd
2 changed files with 44 additions and 2 deletions
+35
View File
@@ -29,4 +29,39 @@ class Nominee extends Model
return null;
}
public function getEducationAttribute($value)
{
$longString = $value;
// Regular expression pattern to match the delimiter followed by any character and a newline or end of string
$pattern = "/\d+\.\s*(.+?)(?=\d+\.\s|$)/";
// Tokenize the string into an array using preg_split
$tokens = preg_split($pattern, $longString, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
// Clean up leading and trailing whitespace from each element
$tokens = array_map('trim', $tokens);
return $tokens;
}
public function getExperienceAttribute($value)
{
$longString = $value;
//newline
// Regular expression pattern to match the delimiter followed by any character and a newline or end of string
$pattern = "/\d+\.\s*(.+?)(?:\n|$)/";
// Tokenize the string into an array using preg_split
$tokens = preg_split($pattern, $longString, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
// Clean up leading and trailing whitespace from each element
$tokens = array_map('trim', $tokens);
return $tokens;
}
}