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
29 changes: 26 additions & 3 deletions app/Livewire/PartnerContentComponent.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php
namespace App\Livewire;

use App\Partner;
use Livewire\Component;
use Livewire\WithPagination;

class PartnerContentComponent extends Component
{
use WithPagination;

/** @var array<int, object>|null Lazy-filled default partners list (used when DB is empty). */
private static $defaultPartnersRaw = null;

public $filter = 'Partners';

public $selectedPartner = null;
Expand Down Expand Up @@ -87,7 +91,13 @@ public function mount()

private function getAllPartners()
{
return collect([
$fromDb = Partner::active()->ordered()->get();
if ($fromDb->isNotEmpty()) {
return $fromDb->map(fn (Partner $p) => $p->toPartnerObject());
}

if (self::$defaultPartnersRaw === null) {
self::$defaultPartnersRaw = [
(object)[
'id' => 1,
'name' => 'JA EUROPE',
Expand Down Expand Up @@ -576,10 +586,23 @@ private function getAllPartners()
'link_url' => 'https://www.athenarc.gr/en',
'main_img_url' => 'images/partners/Athena_RC_logo.png'
],
]);
];
}
return collect(self::$defaultPartnersRaw);
}

/**
* Return default partners as array of arrays (for seeding into DB). Call after getAllPartners() or ensure defaults are loaded.
*/
public static function getDefaultPartnersForSeeding(): array
{
if (self::$defaultPartnersRaw === null) {
(new self())->getAllPartners();
}
return array_map(fn ($o) => (array) $o, self::$defaultPartnersRaw);
}

public function render()
public function render()
{
if ($this->filter === 'Council Presidency') {
// Council Presidency content
Expand Down
93 changes: 93 additions & 0 deletions app/Nova/Partner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;

class Partner extends Resource
{
public static $group = 'Content';

public static $model = \App\Partner::class;

public static $title = 'name';

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

public static function label()
{
return 'Partners & Sponsors';
}

public static function singularLabel()
{
return 'Partner / Sponsor';
}

public static function authorizedToViewAny(Request $request): bool
{
return true;
}

public function fields(Request $request): array
{
return [
ID::make()->sortable(),

Text::make('Name', 'name')
->nullable()
->help('Display name. Optional for sponsor logos (e.g. EU Code Week Supporters).'),

Text::make('Logo URL', 'logo_url')
->rules('required')
->help('Path from site root, e.g. images/partners/logo.png (no leading slash), or full URL.'),

Select::make('Category', 'categories')
->options([
'Partners' => 'Partners',
'Sponsor' => 'EU Code Week Supporters (Sponsor)',
])
->help('Partners = "Partners" tab; Sponsor = "EU Code Week Supporters" tab.')
->resolveUsing(function ($value) {
$arr = is_array($value) ? $value : (array) json_decode($value ?? '[]', true);
return $arr[0] ?? null;
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$v = $request->get($requestAttribute);
$model->{$attribute} = $v !== null && $v !== '' ? [$v] : [];
}),

Textarea::make('Description', 'description')
->nullable()
->help('HTML allowed. Shown when partner is selected (Partners tab only).'),

Text::make('Link URL', 'link_url')
->nullable()
->help('Website URL for "Visit Partner" link.'),

Text::make('Main image URL', 'main_img_url')
->nullable()
->help('Larger image path (optional).'),

Number::make('Position', 'position')
->min(0)
->default(0)
->help('Order on partners page (lower = first).'),

Boolean::make('Active', 'active')
->help('Inactive partners are hidden from the sponsors page.'),
];
}

public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('position')->orderBy('id');
}
}
51 changes: 51 additions & 0 deletions app/Partner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Partner extends Model
{
protected $fillable = [
'name',
'logo_url',
'categories',
'description',
'link_url',
'main_img_url',
'position',
'active',
];

protected $casts = [
'categories' => 'array',
'active' => 'boolean',
'position' => 'integer',
];

public function scopeOrdered($query)
{
return $query->orderBy('position')->orderBy('id');
}

public function scopeActive($query)
{
return $query->where('active', true);
}

/**
* Convert to the same stdClass shape used by the Livewire component (id, name, logo_url, categories, description, link_url, main_img_url).
*/
public function toPartnerObject(): \stdClass
{
$o = new \stdClass;
$o->id = $this->id;
$o->name = $this->name;
$o->logo_url = $this->logo_url;
$o->categories = $this->categories ?? [];
$o->description = $this->description;
$o->link_url = $this->link_url;
$o->main_img_url = $this->main_img_url;
return $o;
}
}
29 changes: 29 additions & 0 deletions database/migrations/2026_02_09_190000_create_partners_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('partners', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->string('logo_url');
$table->json('categories')->nullable(); // ['Partners'] or ['Sponsor']
$table->longText('description')->nullable();
$table->string('link_url')->nullable();
$table->string('main_img_url')->nullable();
$table->unsignedInteger('position')->default(0);
$table->boolean('active')->default(true);
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('partners');
}
};
41 changes: 41 additions & 0 deletions database/seeders/PartnerSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Database\Seeders;

use App\Livewire\PartnerContentComponent;
use App\Partner;
use Illuminate\Database\Seeder;

class PartnerSeeder extends Seeder
{
/**
* Seed partners from the component's default list (current hardcoded partners).
* Run once after migration to move partners into the DB so they can be edited in Nova.
* Safe to run multiple times: only inserts when the table is empty.
*/
public function run(): void
{
if (Partner::count() > 0) {
$this->command->info('Partners table already has data. Skipping seed. Delete partners first to re-seed from defaults.');

return;
}

$defaults = PartnerContentComponent::getDefaultPartnersForSeeding();

foreach ($defaults as $i => $row) {
Partner::create([
'name' => $row['name'] ?? null,
'logo_url' => $row['logo_url'] ?? '',
'categories' => $row['categories'] ?? ['Partners'],
'description' => $row['description'] ?? null,
'link_url' => $row['link_url'] ?? null,
'main_img_url' => $row['main_img_url'] ?? null,
'position' => $i,
'active' => true,
]);
}

$this->command->info('Seeded ' . count($defaults) . ' partners. You can now edit them in Nova.');
}
}
Loading