controller refactoring part 5

This commit is contained in:
Peter Papp
2021-07-20 11:23:45 +02:00
parent 8c493395c4
commit cde8b6aae3
25 changed files with 378 additions and 334 deletions
@@ -10,7 +10,7 @@ use Support\Demo\Actions\DemoService;
use Cartalyst\Stripe\Exception\UnauthorizedException;
use Symfony\Component\HttpKernel\Exception\HttpException;
class SettingController extends Controller
class AdminSettingsController extends Controller
{
public function __construct(
private DemoService $demo
@@ -0,0 +1,43 @@
<?php
namespace Domain\Settings\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Domain\Settings\Models\Setting;
class SettingsController
{
/**
* List of allowed settings to get from public request
*/
private array $blacklist = [
'purchase_code',
'license',
];
/**
* Get selected settings from public route
*/
public function __invoke(
Request $request
): Collection {
if (str_contains($request->get('column'), '|')) {
$columns = collect(explode('|', $request->get('column')))
->each(function ($column) {
if (in_array($column, $this->blacklist)) {
abort(401);
}
});
return Setting::whereIn('name', $columns)
->pluck('value', 'name');
}
if (in_array($request->get('column'), $this->blacklist)) {
abort(401);
}
return Setting::where('name', $request->get('column'))
->pluck('value', 'name');
}
}