Files
E-Vote/app/Nominee.php
T
2024-04-28 11:48:23 +08:00

68 lines
1.6 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Nominee extends Model
{
protected $table = 'nominee';
protected $fillable = [
'name',
'unit',
'no_anggota',
'position_id',
'partylist_id',
'election_id',
'experience',
'education',
'photo',
];
public $timestamp = false;
public function getPhotoAttribute($value)
{
if ($value) {
return base64_encode($value);
}
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;
}
}