Skip to content

Commit bd3c11d

Browse files
author
Emmanuel Obua
committed
added a date format config to control the date format on the location models
1 parent 8dc421c commit bd3c11d

File tree

7 files changed

+115
-0
lines changed

7 files changed

+115
-0
lines changed

src/Models/County.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
class County extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
17+
918
protected $fillable = ['name', 'district_id'];
1019

1120
public function district()
@@ -17,4 +26,14 @@ public function subCounties()
1726
{
1827
return $this->hasMany(SubCounty::class);
1928
}
29+
30+
public function getCreatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
33+
}
34+
35+
public function getUpdatedAtAttribute()
36+
{
37+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
38+
}
2039
}

src/Models/District.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
class District extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
17+
918
protected $fillable = ['name','region_id'];
1019

1120
public function region()
@@ -17,4 +26,14 @@ public function counties()
1726
{
1827
return $this->hasMany(County::class);
1928
}
29+
30+
public function getCreatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
33+
}
34+
35+
public function getUpdatedAtAttribute()
36+
{
37+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
38+
}
2039
}

src/Models/Parish.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
class Parish extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
17+
918
protected $fillable = ['name', 'sub_county_id'];
1019

1120
public function subCounty()
@@ -17,4 +26,14 @@ public function villages()
1726
{
1827
return $this->hasMany(Village::class);
1928
}
29+
30+
public function getCreatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
33+
}
34+
35+
public function getUpdatedAtAttribute()
36+
{
37+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
38+
}
2039
}

src/Models/Region.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@
66

77
class Region extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
917

1018
protected $fillable = ['name'];
1119

1220
public function districts()
1321
{
1422
return $this->hasMany(District::class);
1523
}
24+
25+
public function getCreatedAtAttribute()
26+
{
27+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
28+
}
29+
30+
public function getUpdatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
33+
}
1634
}

src/Models/SubCounty.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
class SubCounty extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
17+
918
protected $fillable = ['name', 'county_id'];
1019

1120
public function county()
@@ -17,4 +26,14 @@ public function parishes()
1726
{
1827
return $this->hasMany(Parish::class);
1928
}
29+
30+
public function getCreatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
33+
}
34+
35+
public function getUpdatedAtAttribute()
36+
{
37+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
38+
}
2039
}

src/Models/Village.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@
66

77
class Village extends Model
88
{
9+
10+
private $format;
11+
12+
public function __construct()
13+
{
14+
parent::__construct();
15+
$this->format = config('uglocale.date_format', 'd M Y, h:i A');
16+
}
17+
918
protected $fillable = ['name', 'parish_id'];
1019

1120
public function parish()
1221
{
1322
return $this->belongsTo(Parish::class);
1423
}
24+
25+
public function getCreatedAtAttribute()
26+
{
27+
return \Carbon\Carbon::parse($this->attributes['created_at'])->format($this->format);
28+
}
29+
30+
public function getUpdatedAtAttribute()
31+
{
32+
return \Carbon\Carbon::parse($this->attributes['updated_at'])->format($this->format);
33+
}
1534
}
35+

src/config/uglocale.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
return [
44
'batch_size' => env('UGLOCALE_BATCH_SIZE', 1000),
5+
'date_format' => 'd M Y, h:i A'
56
];

0 commit comments

Comments
 (0)