<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LanguageController extends Controller
{
    public function setLocale($locale = null)
    {
        $supportedLocales = config('app.available_locales', ['en', 'sr']);

        if (!$locale || !in_array($locale, $supportedLocales)) {
            return redirect()->back()->with('error', 'Unsupported locale.');
        }

        session(['app_locale' => $locale]);

        return redirect()->back();
    }
}
