Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit a1a329b

Browse files
Add HomeService for homepage data handling and refactor HomeController to use service methods; update welcome page to include dynamic filters.
1 parent 55272eb commit a1a329b

File tree

8 files changed

+199
-77
lines changed

8 files changed

+199
-77
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@
44

55
namespace App\Http\Controllers;
66

7-
use App\Models\UserFilament;
7+
use App\Services\Pages\HomeService;
88
use Inertia\Inertia;
99

1010
class HomeController
1111
{
12-
public function __invoke()
12+
public function __invoke(HomeService $home)
1313
{
14-
$settings = UserFilament::query()
15-
->with([
16-
'machine.vendor',
17-
'filament' => ['vendor', 'type'],
18-
'color',
19-
])
20-
->orderBy('machine_id')
21-
->orderBy('filament_id')
22-
->orderBy('color_id')
23-
->orderBy('id')
24-
->get();
25-
2614
return Inertia::render('welcome', [
27-
'settings' => $settings,
15+
'userFilaments' => $home->userFilaments(),
16+
'machines' => $home->machines(),
17+
'filamentTypes' => $home->filamentTypes(),
18+
'colors' => $home->colors(),
2819
]);
2920
}
3021
}

app/Models/Color.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Casts\HexCast;
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
99
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Database\Eloquent\Relations\HasMany;
1011
use Illuminate\Database\Eloquent\SoftDeletes;
1112

1213
class Color extends Model
@@ -24,4 +25,9 @@ protected function casts(): array
2425
'hex' => HexCast::class,
2526
];
2627
}
28+
29+
public function userFilament(): HasMany
30+
{
31+
return $this->hasMany(UserFilament::class);
32+
}
2733
}

app/Models/Filament.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Database\Eloquent\Factories\HasFactory;
88
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\Relations\HasMany;
910
use Illuminate\Database\Eloquent\Relations\Relation;
1011
use Illuminate\Database\Eloquent\SoftDeletes;
1112

@@ -28,4 +29,9 @@ public function type(): Relation
2829
{
2930
return $this->belongsTo(FilamentType::class, 'filament_type_id', 'id');
3031
}
32+
33+
public function userFilament(): HasMany
34+
{
35+
return $this->hasMany(UserFilament::class);
36+
}
3137
}

app/Models/FilamentType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Database\Eloquent\Factories\HasFactory;
88
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
910
use Illuminate\Database\Eloquent\SoftDeletes;
1011

1112
class FilamentType extends Model
@@ -15,4 +16,16 @@ class FilamentType extends Model
1516
protected $fillable = [
1617
'title',
1718
];
19+
20+
public function userFilaments(): HasManyThrough
21+
{
22+
return $this->hasManyThrough(
23+
UserFilament::class,
24+
Filament::class,
25+
'filament_type_id',
26+
'filament_id',
27+
'id',
28+
'id'
29+
);
30+
}
1831
}

app/Models/Machine.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Events\SluggableEvent;
99
use Illuminate\Database\Eloquent\Factories\HasFactory;
1010
use Illuminate\Database\Eloquent\Model;
11+
use Illuminate\Database\Eloquent\Relations\HasMany;
1112
use Illuminate\Database\Eloquent\Relations\Relation;
1213
use Illuminate\Database\Eloquent\SoftDeletes;
1314

@@ -34,6 +35,11 @@ protected function casts(): array
3435

3536
public function vendor(): Relation
3637
{
37-
return $this->belongsTo(Vendor::class);
38+
return $this->belongsTo(Vendor::class, 'vendor_id', 'id');
39+
}
40+
41+
public function userFilament(): HasMany
42+
{
43+
return $this->hasMany(UserFilament::class);
3844
}
3945
}

app/Models/UserFilament.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ protected function casts(): array
4343

4444
public function user(): BelongsTo
4545
{
46-
return $this->belongsTo(User::class);
46+
return $this->belongsTo(User::class, 'user_id', 'id');
4747
}
4848

4949
public function machine(): BelongsTo
5050
{
51-
return $this->belongsTo(Machine::class);
51+
return $this->belongsTo(Machine::class, 'machine_id', 'id');
5252
}
5353

5454
public function filament(): BelongsTo
5555
{
56-
return $this->belongsTo(Filament::class);
56+
return $this->belongsTo(Filament::class, 'filament_id', 'id');
5757
}
5858

5959
public function color(): BelongsTo
6060
{
61-
return $this->belongsTo(Color::class);
61+
return $this->belongsTo(Color::class, 'color_id', 'id');
6262
}
6363
}

app/Services/Pages/HomeService.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Services\Pages;
6+
7+
use App\Models\Color;
8+
use App\Models\FilamentType;
9+
use App\Models\Machine;
10+
use App\Models\UserFilament;
11+
use Illuminate\Database\Eloquent\Collection;
12+
13+
class HomeService
14+
{
15+
public function machines(): Collection
16+
{
17+
return Machine::query()
18+
->whereHas('userFilament')
19+
->with('vendor')
20+
->orderBy('vendor_id')
21+
->orderBy('title')
22+
->get(['id', 'title', 'vendor_id']);
23+
}
24+
25+
public function filamentTypes(): Collection
26+
{
27+
return FilamentType::query()
28+
->whereHas('userFilaments')
29+
->orderBy('title')
30+
->get(['id', 'title']);
31+
}
32+
33+
public function colors(): Collection
34+
{
35+
return Color::query()
36+
->whereHas('userFilament')
37+
->orderBy('title')
38+
->get(['title', 'hex']);
39+
}
40+
41+
public function userFilaments(): Collection
42+
{
43+
return UserFilament::query()
44+
->with([
45+
'machine.vendor',
46+
'filament' => ['vendor', 'type'],
47+
'color',
48+
])
49+
->orderBy('machine_id')
50+
->orderBy('filament_id')
51+
->orderBy('color_id')
52+
->orderBy('id')
53+
->get();
54+
}
55+
}

resources/js/pages/welcome.tsx

Lines changed: 102 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,113 @@
11
import { Head } from '@inertiajs/react';
22

3-
export default function Welcome({ settings }) {
3+
export default function Welcome({ userFilaments, machines, filamentTypes, colors }) {
44
return (
55
<>
66
<Head title="Welcome" />
77
<div className="flex min-h-screen flex-col items-center bg-[#EDEDFC] p-6 text-[#1b1b18] lg:justify-center lg:p-8 dark:bg-[#0a0a0a]">
88
<div className="flex w-full items-center justify-center opacity-100 transition-opacity duration-750 lg:grow starting:opacity-0">
99
<main className="flex w-full flex-col-reverse lg:max-w-4xl lg:flex-row">
10-
<table className="w-full border-collapse border border-gray-400 bg-white text-sm dark:border-gray-500 dark:bg-gray-800">
11-
<thead>
12-
<tr>
13-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
14-
Printer
15-
</th>
16-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
17-
Filament
18-
</th>
19-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
20-
Color
21-
</th>
22-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
23-
Pressure Advance
24-
</th>
25-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
26-
Flow Ratio
27-
</th>
28-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
29-
Max Volumetric Speed
30-
</th>
31-
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
32-
Nozzle Temperature
33-
</th>
34-
</tr>
35-
</thead>
36-
<tbody>
37-
{ settings.map((setting) => (
38-
<tr key={ setting.id }>
39-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
40-
{ setting.machine.vendor.title }&nbsp;
41-
{ setting.machine.title }
42-
</td>
43-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
44-
{ setting.filament.vendor.title }&nbsp;
45-
{ setting.filament.type.title }<br />
46-
</td>
47-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
48-
{ setting.color.title }
49-
</td>
50-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
51-
{ setting.pressure_advance }
52-
</td>
53-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
54-
{ setting.filament_flow_ratio }
55-
</td>
56-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
57-
{ setting.filament_max_volumetric_speed }
58-
</td>
59-
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
60-
{ setting.nozzle_temperature }
61-
</td>
62-
</tr>
63-
)) }
64-
</tbody>
65-
</table>
10+
<div className="w-full">
11+
<table className="w-full border-collapse border border-gray-400 bg-white text-sm dark:border-gray-500 dark:bg-gray-800 mb-4">
12+
<thead>
13+
<tr>
14+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">Printer</th>
15+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">Filament</th>
16+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">Color</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
22+
<select name="machines" id="machine" className="w-full">
23+
<option value="0">- All -</option>
24+
25+
{ machines.map((item) => (
26+
<option value={ item.id }>{ item.vendor.title }&nbsp;{ item.title }</option>
27+
)) }
28+
</select>
29+
</td>
30+
31+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
32+
<select name="machines" id="machine" className="w-full">
33+
<option value="0">- All -</option>
34+
35+
{ filamentTypes.map((item) => (
36+
<option value={ item.id }>{ item.title }</option>
37+
)) }
38+
</select>
39+
</td>
40+
41+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
42+
<select name="machines" id="machine" className="w-full">
43+
<option value="0">- All -</option>
44+
45+
{ colors.map((item) => (
46+
<option value={ item.id }>{ item.title }</option>
47+
)) }
48+
</select>
49+
</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
54+
<table className="border-collapse border border-gray-400 bg-white text-sm dark:border-gray-500 dark:bg-gray-800">
55+
<thead>
56+
<tr>
57+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
58+
Printer
59+
</th>
60+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
61+
Filament
62+
</th>
63+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
64+
Color
65+
</th>
66+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
67+
Pressure Advance
68+
</th>
69+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
70+
Flow Ratio
71+
</th>
72+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
73+
Max Volumetric Speed
74+
</th>
75+
<th className="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
76+
Nozzle Temperature
77+
</th>
78+
</tr>
79+
</thead>
80+
<tbody>
81+
{ userFilaments.map((item) => (
82+
<tr key={ item.id }>
83+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
84+
{ item.machine.vendor.title }&nbsp;
85+
{ item.machine.title }
86+
</td>
87+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
88+
{ item.filament.vendor.title }&nbsp;
89+
{ item.filament.type.title }<br />
90+
</td>
91+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
92+
{ item.color.title }
93+
</td>
94+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
95+
{ item.pressure_advance }
96+
</td>
97+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
98+
{ item.filament_flow_ratio }
99+
</td>
100+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
101+
{ item.filament_max_volumetric_speed }
102+
</td>
103+
<td className="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
104+
{ item.nozzle_temperature }
105+
</td>
106+
</tr>
107+
)) }
108+
</tbody>
109+
</table>
110+
</div>
66111
</main>
67112
</div>
68113
</div>

0 commit comments

Comments
 (0)