Skip to content

Commit a694992

Browse files
authored
Merge pull request #3303 from codeeu/dev
Dev
2 parents 3ddef72 + e971af0 commit a694992

5 files changed

Lines changed: 65 additions & 15 deletions

File tree

‎app/HomeSlide.php‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class HomeSlide extends Model
1111
'description',
1212
'url',
1313
'button_text',
14+
'open_primary_new_tab',
1415
'url2',
1516
'button2_text',
17+
'open_second_new_tab',
1618
'image',
1719
'position',
1820
'active',
@@ -25,6 +27,8 @@ class HomeSlide extends Model
2527
'show_countdown' => 'boolean',
2628
'countdown_target' => 'datetime',
2729
'position' => 'integer',
30+
'open_primary_new_tab' => 'boolean',
31+
'open_second_new_tab' => 'boolean',
2832
];
2933

3034
public function scopeActive($query)
@@ -38,16 +42,17 @@ public function scopeOrdered($query)
3842
}
3943

4044
/**
41-
* Full URL for image (prefix with base URL if stored as path).
45+
* Full URL for image. Use asset() for paths so images in public/ resolve correctly.
4246
*/
4347
public function getImageUrlAttribute(): ?string
4448
{
4549
if (empty($this->image)) {
4650
return null;
4751
}
48-
if (str_starts_with($this->image, 'http://') || str_starts_with($this->image, 'https://')) {
49-
return $this->image;
52+
$value = trim($this->image);
53+
if (str_starts_with($value, 'http://') || str_starts_with($value, 'https://')) {
54+
return $value;
5055
}
51-
return url(ltrim($this->image, '/'));
56+
return asset(ltrim($value, '/'));
5257
}
5358
}

‎app/Http/Controllers/HomeController.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ private function getActivities()
3030
'description' => $slide->description ?? '',
3131
'url' => $slide->url,
3232
'btn_lang' => $slide->button_text,
33+
'open_primary_new_tab' => $slide->open_primary_new_tab ?? false,
3334
'url2' => $slide->url2,
3435
'btn2_lang' => $slide->button2_text,
36+
'open_second_new_tab' => $slide->open_second_new_tab ?? false,
3537
'image' => $slide->image_url,
3638
'show_countdown' => $slide->show_countdown,
3739
'countdown_target' => $slide->countdown_target?->toIso8601String(),
@@ -54,8 +56,10 @@ private function getActivities()
5456
'description' => 'home.banner5_description',
5557
'url' => '/future-ready-csr',
5658
'btn_lang' => 'home.learn_more',
59+
'open_primary_new_tab' => false,
5760
'url2' => null,
5861
'btn2_lang' => null,
62+
'open_second_new_tab' => false,
5963
'image' => $defaultImages[0] ?? null,
6064
'show_countdown' => false,
6165
'countdown_target' => null,
@@ -65,8 +69,10 @@ private function getActivities()
6569
'description' => 'home.banner4_description',
6670
'url' => 'https://codeweek.eu/blog/code-week-digital-educator-awards-2025/',
6771
'btn_lang' => 'home.view_winners',
72+
'open_primary_new_tab' => false,
6873
'url2' => 'https://codeweek.eu/blog/code-week-digital-educator-awards-2025/',
6974
'btn2_lang' => null,
75+
'open_second_new_tab' => false,
7076
'image' => $defaultImages[1] ?? null,
7177
'show_countdown' => false,
7278
'countdown_target' => null,
@@ -76,8 +82,10 @@ private function getActivities()
7682
'description' => 'home.banner6_description',
7783
'url' => 'https://airtable.com/appW5W6DJ6CI6SVdH/pagLDrU2NQja9F2vu/form',
7884
'btn_lang' => 'home.register_here',
85+
'open_primary_new_tab' => false,
7986
'url2' => null,
8087
'btn2_lang' => null,
88+
'open_second_new_tab' => false,
8189
'image' => $defaultImages[2] ?? null,
8290
'show_countdown' => false,
8391
'countdown_target' => null,
@@ -87,8 +95,10 @@ private function getActivities()
8795
'description' => 'home.when_text',
8896
'url' => '/guide',
8997
'btn_lang' => 'home.get_involved',
98+
'open_primary_new_tab' => false,
9099
'url2' => '/blog/code-week-25-programme/',
91100
'btn2_lang' => null,
101+
'open_second_new_tab' => false,
92102
'image' => $defaultImages[3] ?? null,
93103
'show_countdown' => false,
94104
'countdown_target' => null,

‎app/Nova/HomeSlide.php‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ public function fields(Request $request): array
4242
ID::make()->sortable(),
4343
Text::make('Title', 'title')
4444
->rules('required')
45-
->help('Lang key (e.g. home.banner1_title) or plain text.'),
45+
->help('Use a lang key (e.g. home.banner1_title) for translated content, or type plain text.'),
4646
Textarea::make('Description', 'description')
4747
->nullable()
48-
->help('Lang key or plain text.'),
48+
->help('Use a lang key for translated content, or plain text.'),
4949
Text::make('Primary button URL', 'url')->rules('required')->hideFromIndex(),
5050
Text::make('Primary button label', 'button_text')
5151
->rules('required')
52-
->help('Lang key (e.g. home.learn_more) or plain text.'),
52+
->help('Lang key (e.g. home.learn_more) for translation, or plain text.'),
53+
Boolean::make('Open primary link in new tab', 'open_primary_new_tab')
54+
->help('Open the primary button link in a new window/tab.'),
5355
Text::make('Second button URL', 'url2')->nullable()->hideFromIndex(),
5456
Text::make('Second button label', 'button2_text')
5557
->nullable()
56-
->help('Leave empty to hide second button.'),
58+
->help('Leave empty to hide second button. Use lang key for translation.'),
59+
Boolean::make('Open second link in new tab', 'open_second_new_tab')
60+
->help('Open the second button link in a new window/tab.'),
5761
Text::make('Image', 'image')
5862
->nullable()
59-
->help('Path e.g. /images/homepage/slide1.png or full URL. Used as slide background.'),
63+
->help('Path from site root e.g. images/dream-jobs/dream_jobs_bg.png (no leading slash), or full URL. Used as slide background.'),
6064
Number::make('Position', 'position')
6165
->min(0)
6266
->default(0)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('home_slides', function (Blueprint $table) {
15+
$table->boolean('open_primary_new_tab')->default(false)->after('button_text');
16+
$table->boolean('open_second_new_tab')->default(false)->after('button2_text');
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::table('home_slides', function (Blueprint $table) {
26+
$table->dropColumn(['open_primary_new_tab', 'open_second_new_tab']);
27+
});
28+
}
29+
};

‎resources/views/static/home.blade.php‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,24 @@ function countdownTimer(targetDate) {
9090

9191
<h2
9292
class="text-[#1C4DA1] text-[30px] md:text-[60px] leading-9 md:leading-[72px] font-normal font-['Montserrat'] mb-4 max-w-[525px]">
93-
@lang($activity['title'])
93+
{{ __($activity['title']) }}
9494
</h2>
9595
<p
9696
class="text-xl md:text-2xl leading-8 text-[#333E48] p-0 mb-4 max-md:max-w-full max-w-[525px]">
9797
{{ strip_tags(__($activity['description'] ?? '')) }}
9898
</p>
9999
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
100100
<a class="inline-block bg-primary hover:bg-hover-orange rounded-full py-4 px-6 md:px-10 font-semibold text-base w-full md:w-auto text-center text-[#20262C] transition-all duration-300"
101-
href="{{ $activity['url'] }}">
102-
@lang($activity['btn_lang'])
101+
href="{{ $activity['url'] }}"
102+
@if(!empty($activity['open_primary_new_tab'])) target="_blank" rel="noopener noreferrer" @endif>
103+
{{ __($activity['btn_lang']) }}
103104
</a>
104105

105-
@if (isset($activity['btn2_lang']) && !is_null($activity['btn2_lang']))
106+
@if (isset($activity['btn2_lang']) && !is_null($activity['btn2_lang']) && $activity['btn2_lang'] !== '')
106107
<a class="flex justify-center items-center gap-2 text-[#1C4DA1] border-solid border-2 border-[#1C4DA1] rounded-full py-3 px-8 font-semibold text-lg transition-all duration-300 hover:bg-[#E8EDF6] group"
107-
target="_blank" href="{{ $activity['url2'] }}">
108-
<span>@lang($activity['btn2_lang'])</span>
108+
href="{{ $activity['url2'] }}"
109+
@if(!empty($activity['open_second_new_tab'])) target="_blank" rel="noopener noreferrer" @endif>
110+
<span>{{ __($activity['btn2_lang']) }}</span>
109111
<div class="flex overflow-hidden gap-2 w-4">
110112
<img src="/images/arrow-right-icon.svg"
111113
class="duration-500 transform -translate-x-6 min-w-4 group-hover:translate-x-0" />

0 commit comments

Comments
 (0)