49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Theme;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ThemeController extends Controller
|
|
{
|
|
// List themes (for the scene theme picker and the app).
|
|
public function index(Request $request)
|
|
{
|
|
$query = Theme::query();
|
|
|
|
if (!$request->boolean('include_inactive')) {
|
|
$query->where('is_active', true);
|
|
}
|
|
|
|
return response()->json($query->orderBy('order')->get());
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
return response()->json(Theme::findOrFail($id));
|
|
}
|
|
|
|
// Edit an existing theme — typically its color map. The `key` is the stable
|
|
// identifier the app maps against, so it is intentionally not editable here.
|
|
public function update(Request $request, $id)
|
|
{
|
|
$theme = Theme::findOrFail($id);
|
|
|
|
$data = $request->validate([
|
|
'name' => 'sometimes|string|max:255',
|
|
'colors' => 'sometimes|array',
|
|
'colors.*' => 'nullable|string|max:32',
|
|
'order' => 'sometimes|integer',
|
|
'is_active' => 'sometimes|boolean',
|
|
]);
|
|
|
|
$theme->update($data);
|
|
|
|
return response()->json([
|
|
'message' => 'Theme updated successfully',
|
|
'data' => $theme,
|
|
]);
|
|
}
|
|
}
|