-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathHackathonsPage.php
More file actions
64 lines (55 loc) · 1.53 KB
/
HackathonsPage.php
File metadata and controls
64 lines (55 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class HackathonsPage extends Model
{
protected $table = 'hackathons_page';
protected $fillable = [
'dynamic_content',
'hero_title',
'hero_subtitle',
'hero_background_image_url',
'intro_title',
'intro_paragraph_1',
'intro_paragraph_2',
'details_title',
'details_paragraph_1',
'details_paragraph_2',
'details_paragraph_3',
'details_paragraph_4',
'video_url',
'video_poster_image_url',
'extra_button_text',
'extra_button_link',
'recap_button_text',
'recap_button_link',
'toolkit_button_text',
'toolkit_button_link',
'locale_overrides',
];
protected $casts = [
'dynamic_content' => 'boolean',
'locale_overrides' => 'array',
];
public static function config(): self
{
$page = self::first();
if ($page) {
return $page;
}
return self::create([
'dynamic_content' => false,
'locale_overrides' => null,
]);
}
public function contentForLocale(string $key, ?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$overrides = $this->locale_overrides ?? [];
if (!empty($overrides[$locale][$key])) {
return (string) $overrides[$locale][$key];
}
$value = $this->getAttribute($key);
return $value !== null ? (string) $value : '';
}
}