public function back($locale, Request $request)
    {
        $this->setLocale($locale, $request);

        $session = $request->session();

        if (config('language.url')) {
            $previous_url = substr(str_replace(env('APP_URL'), '', $session->previousUrl()), 7);

            if (strlen($previous_url) == 3) {
                $previous_url = substr($previous_url, 3);
            } else {
                $previous_url = substr($previous_url, strrpos($previous_url, '/') + 1);
            }

            $url = rtrim(env('APP_URL'), '/') . '/' . $locale . '/' . ltrim($previous_url, '/');

            $session->setPreviousUrl($url);
        }

        return redirect($session->previousUrl());
    }
public function back($locale, Request $request)
    {
        $this->setLocale($locale, $request);

        $session = $request->session();

        if (config('language.url')) {
            $previous_url = substr(str_replace(env('APP_URL'), '', $session->previousUrl()), 7);

            if (strlen($previous_url) == 3) {
                $previous_url = substr($previous_url, 3);
            } else {
                $previous_url = substr($previous_url, strrpos($previous_url, '/') + 1);
            }

            $url = rtrim(env('APP_URL'), '/') . '/' . $locale . '/' . ltrim($previous_url, '/');

            $session->setPreviousUrl($url);
        }

        return redirect($session->previousUrl());
    }
public function back ( $ locale , Request $ request ) { $ this -> setLocale ( $ locale , $ request ) ; $ session = $ request -> session ( ) ; if ( config ( 'language.url' ) ) { $ previous_url = substr ( str_replace ( env ( 'APP_URL' ) , '' , $ session -> previousUrl ( ) ) , 7 ) ; if ( strlen ( $ previous_url ) == 3 ) { $ previous_url = substr ( $ previous_url , 3 ) ; } else { $ previous_url = substr ( $ previous_url , strrpos ( $ previous_url , '/' ) + 1 ) ; } $ url = rtrim ( env ( 'APP_URL' ) , '/' ) . '/' . $ locale . '/' . ltrim ( $ previous_url , '/' ) ; $ session -> setPreviousUrl ( $ url ) ; } return redirect ( $ session -> previousUrl ( ) ) ; }
Set locale and return back.

@param string                   $locale
@param \Illuminate\Http\Request $request

@return string
Set locale and return back .