Skip to content

Commit 4737313

Browse files
committed
theme swither
1 parent 3650884 commit 4737313

19 files changed

Lines changed: 2280 additions & 674 deletions

app/Http/Controllers/ThemesController.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,36 @@ class ThemesController extends Controller
99
{
1010
public function index(Registry $registry)
1111
{
12-
$themes = $registry->themes()->paginate(12);
12+
$query = $registry->themes();
13+
14+
if ($search = request('search')) {
15+
$query->where(function ($q) use ($search) {
16+
$q->where('name', 'like', "%{$search}%")
17+
->orWhere('title', 'like', "%{$search}%")
18+
->orWhere('description', 'like', "%{$search}%");
19+
});
20+
}
21+
22+
if ($category = request('category')) {
23+
$query->whereJsonContains('categories', $category);
24+
}
25+
26+
$themes = $query->paginate(12)->withQueryString();
27+
28+
$availableCategories = $registry->themes()
29+
->select('categories')
30+
->get()
31+
->pluck('categories')
32+
->flatten()
33+
->unique()
34+
->sort()
35+
->values()
36+
->all();
1337

1438
return Inertia::render('themes/index', [
1539
'themes' => $themes,
40+
'filters' => request()->only(['search', 'category']),
41+
'availableCategories' => $availableCategories,
1642
]);
1743
}
1844
}

app/Models/Registry.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Eloquent\Attributes\Fillable;
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910
use Illuminate\Database\Eloquent\SoftDeletes;
1011

1112
#[Fillable([
@@ -34,6 +35,15 @@ class Registry extends Model
3435
{
3536
use HasRegistry, SoftDeletes;
3637

38+
// =========================================================================
39+
// Relationships
40+
// =========================================================================
41+
42+
public function user(): BelongsTo
43+
{
44+
return $this->belongsTo(User::class);
45+
}
46+
3747
// =========================================================================
3848
// Casts
3949
// =========================================================================

app/Models/User.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Database\Eloquent\Attributes\Fillable;
99
use Illuminate\Database\Eloquent\Attributes\Hidden;
1010
use Illuminate\Database\Eloquent\Factories\HasFactory;
11+
use Illuminate\Database\Eloquent\Relations\HasMany;
1112
use Illuminate\Database\Eloquent\SoftDeletes;
1213
use Illuminate\Foundation\Auth\User as Authenticatable;
1314
use Illuminate\Notifications\Notifiable;
@@ -21,6 +22,11 @@ class User extends Authenticatable implements MustVerifyEmail
2122
/** @use HasFactory<UserFactory> */
2223
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
2324

25+
public function registries(): HasMany
26+
{
27+
return $this->hasMany(Registry::class);
28+
}
29+
2430
/**
2531
* Get the attributes that should be cast.
2632
*

database/migrations/2026_05_02_175933_create_registries_table.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
public function up(): void
109
{
1110
Schema::create('registries', function (Blueprint $table) {
1211
$table->id();
1312

13+
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
14+
1415
// ── Core identity ────────────────────────────────────────────────
1516
$table->string('name')->unique()->comment('Unique registry item identifier');
1617
$table->string('type')->comment(
17-
'registry:lib | registry:block | registry:component | registry:ui | '.
18-
'registry:hook | registry:theme | registry:page | registry:file | '.
18+
'registry:lib | registry:block | registry:component | registry:ui | ' .
19+
'registry:hook | registry:theme | registry:page | registry:file | ' .
1920
'registry:style | registry:base | registry:font | registry:item'
2021
);
2122
$table->string('title')->nullable()->comment('Human-readable title');

database/seeders/DatabaseSeeder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function run(): void
1717
// User::factory(10)->create();
1818

1919
User::factory()->create([
20-
'name' => 'Test User',
21-
'email' => 'test@example.com',
20+
'name' => 'Claude Myburgh',
21+
'email' => 'claude@designbycode.co.za',
2222
]);
2323

2424
$this->call([

0 commit comments

Comments
 (0)