<?php

namespace App\Http\Controllers\Admin;

use App\Configuration;
use App\Facade\UserConfig;
use App\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Request;

class StatisticsController extends Controller
{
    public function save(Request $request)
    {
        $isPublicStatsEnabled = strtolower($request->get('enable_public_statistics')) == 'on';

        /** @var Configuration $config */
        $config = UserConfig::getOrCreateModel('public_statistics');
        $config->value = $isPublicStatsEnabled;
        $config->save();

        $request->session()->flash('success', trans('admin.statistics_prefs_saved_message'));
        return redirect(route('statistics.index'));
    }
}