Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions app/HomeSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class HomeSlide extends Model
{
protected $fillable = [
'title_translations',
'description_translations',
'title',
'description',
'url',
'button_text_translations',
'button_text',
'open_primary_new_tab',
'url2',
'button2_text_translations',
'button2_text',
'open_second_new_tab',
'image',
'position',
Expand All @@ -23,10 +23,6 @@ class HomeSlide extends Model
];

protected $casts = [
'title_translations' => 'array',
'description_translations' => 'array',
'button_text_translations' => 'array',
'button2_text_translations' => 'array',
'active' => 'boolean',
'show_countdown' => 'boolean',
'countdown_target' => 'datetime',
Expand All @@ -35,30 +31,6 @@ class HomeSlide extends Model
'open_second_new_tab' => 'boolean',
];

/**
* Get translated string for a key (title_translations, description_translations, etc.).
* Uses current app locale with fallback to 'en' then first available.
*/
public function getTranslation(string $key, ?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$translations = $this->getAttribute($key);
if (! is_array($translations)) {
return '';
}
$value = $translations[$locale] ?? $translations['en'] ?? null;
if ($value !== null && $value !== '') {
return (string) $value;
}
return (string) (array_values($translations)[0] ?? '');
}

/** For Nova index/detail: show title in current locale. */
public function getTitleAttribute(): string
{
return $this->getTranslation('title_translations');
}

public function scopeActive($query)
{
return $query->where('active', true);
Expand Down
11 changes: 5 additions & 6 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ private function getActivities()
if (Schema::hasTable('home_slides')) {
$slides = HomeSlide::active()->ordered()->get();
if ($slides->isNotEmpty()) {
$locale = app()->getLocale();
return $slides->map(function (HomeSlide $slide) use ($locale) {
return $slides->map(function (HomeSlide $slide) {
return [
'title' => $slide->getTranslation('title_translations', $locale),
'description' => $slide->getTranslation('description_translations', $locale),
'title' => $slide->title,
'description' => $slide->description ?? '',
'url' => $slide->url,
'btn_lang' => $slide->getTranslation('button_text_translations', $locale),
'btn_lang' => $slide->button_text,
'open_primary_new_tab' => $slide->open_primary_new_tab ?? false,
'url2' => $slide->url2,
'btn2_lang' => $slide->getTranslation('button2_text_translations', $locale),
'btn2_lang' => $slide->button2_text,
'open_second_new_tab' => $slide->open_second_new_tab ?? false,
'image' => $slide->image_url,
'show_countdown' => $slide->show_countdown,
Expand Down
30 changes: 12 additions & 18 deletions app/Nova/HomeSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\KeyValue;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;

class HomeSlide extends Resource
Expand All @@ -19,7 +19,7 @@ class HomeSlide extends Resource

public static $title = 'title';

public static $search = [];
public static $search = ['title', 'description'];

public static function label()
{
Expand All @@ -40,28 +40,22 @@ public function fields(Request $request): array
{
return [
ID::make()->sortable(),
KeyValue::make('Title', 'title_translations')
->keyLabel('Locale (e.g. en, fr, de)')
->valueLabel('Text')
Text::make('Title', 'title')
->rules('required')
->help('Add one row per language. Key = locale code (en, fr, de, …), Value = translated title.'),
KeyValue::make('Description', 'description_translations')
->keyLabel('Locale')
->valueLabel('Text')
->help('Add one row per language.'),
->help('Use a lang key (e.g. home.banner1_title) for translated content, or type plain text.'),
Textarea::make('Description', 'description')
->nullable()
->help('Use a lang key for translated content, or plain text.'),
Text::make('Primary button URL', 'url')->rules('required')->hideFromIndex(),
KeyValue::make('Primary button label', 'button_text_translations')
->keyLabel('Locale')
->valueLabel('Text')
Text::make('Primary button label', 'button_text')
->rules('required')
->help('Add one row per language.'),
->help('Lang key (e.g. home.learn_more) for translation, or plain text.'),
Boolean::make('Open primary link in new tab', 'open_primary_new_tab')
->help('Open the primary button link in a new window/tab.'),
Text::make('Second button URL', 'url2')->nullable()->hideFromIndex(),
KeyValue::make('Second button label', 'button2_text_translations')
->keyLabel('Locale')
->valueLabel('Text')
->help('Add one row per language. Leave empty to hide second button.'),
Text::make('Second button label', 'button2_text')
->nullable()
->help('Leave empty to hide second button. Use lang key for translation.'),
Boolean::make('Open second link in new tab', 'open_second_new_tab')
->help('Open the second button link in a new window/tab.'),
Text::make('Image', 'image')
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions resources/views/static/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class="text-[#1C4DA1] text-[30px] md:text-[60px] leading-9 md:leading-[72px] fon
</h2>
<p
class="text-xl md:text-2xl leading-8 text-[#333E48] p-0 mb-4 max-md:max-w-full max-w-[525px]">
{!! strip_tags(__($activity['description'] ?? '')) !!}
{{ strip_tags(__($activity['description'] ?? '')) }}
</p>
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
<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"
Expand All @@ -103,7 +103,7 @@ class="text-xl md:text-2xl leading-8 text-[#333E48] p-0 mb-4 max-md:max-w-full m
{{ __($activity['btn_lang']) }}
</a>

@if (isset($activity['btn2_lang']) && (string)$activity['btn2_lang'] !== '')
@if (isset($activity['btn2_lang']) && !is_null($activity['btn2_lang']) && $activity['btn2_lang'] !== '')
<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"
href="{{ $activity['url2'] }}"
@if(!empty($activity['open_second_new_tab'])) target="_blank" rel="noopener noreferrer" @endif>
Expand Down
Loading