rappasoft/laravel-boilerplate

/lang route will break the session if wrong...

mikkeaa opened this issue · 2 comments

If user manually set a /lang route and puts in something "bad ex:
http://localhost:8000/lang/qwerty
-Will lead to "Undefined array key", not found in lang array...
-It is set by the LocaleController to the session, and it won't go away until session is reset.
-Should there be a check "if exists" ?
-Also there's no auth on the /lang route.

Something like this, is what I had in mind:
Http/Controllers/LocaleController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Arr;

/**
 * Class LocaleController.
 */
class LocaleController
{
    /**
     * @param $locale
     * @return \Illuminate\Http\RedirectResponse
     */
    public function change($locale)
    {
        if(Arr::exists(config('boilerplate.locale.languages'),$locale)){
            app()->setLocale($locale);
            session()->put('locale', $locale);
        }
        return redirect()->back();
    }
}
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.