mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-14 09:01:42 -04:00
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\StudioPlus\Http\Controllers\API;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\StudioPlus\Entities\GlobalSetting;
|
|
use Modules\StudioPlus\Http\Requests\GlobalSettingRequest;
|
|
use Modules\StudioPlus\Transformers\GlobalSettingResource;
|
|
|
|
class GlobalSettingController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$types = $request->input('types');
|
|
$explodedTypes = explode(',', $types);
|
|
|
|
$settings = GlobalSetting::query()
|
|
->when($request->filled('types'), fn ($query) => $query->whereIn('type', $explodedTypes))
|
|
->get();
|
|
|
|
return GlobalSettingResource::collection($settings);
|
|
}
|
|
|
|
public function store(GlobalSettingRequest $request)
|
|
{
|
|
GlobalSetting::create($request->validated());
|
|
|
|
return response()->noContent();
|
|
}
|
|
|
|
public function activate(GlobalSetting $globalSetting)
|
|
{
|
|
GlobalSetting::query()
|
|
->where('type', $globalSetting->type)
|
|
->update([
|
|
'is_active' => 0
|
|
]);
|
|
|
|
$globalSetting->update([
|
|
'is_active' => !$globalSetting->is_active
|
|
]);
|
|
|
|
return response()->noContent();
|
|
}
|
|
|
|
public function getActive(Request $request)
|
|
{
|
|
return GlobalSetting::query()
|
|
->when($request->filled('type'), fn ($query) => $query->where('type', $request->type))
|
|
->where('is_active', 1)
|
|
->latest()
|
|
->first();
|
|
}
|
|
}
|