I have a class like this:
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
// I need to put a if() in here
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
// there is some other methods in here
}
As I've commented in the code above (// I need to put a if() in here
), I need to compare something in there and use the result as $redirectTo
variable's value.
But PHP doesn't let me to do that. I mean, I want something like this:
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
if ( Lang::getLocale() == 'en' ){
$lang = '/en';
} else {
$lang = '/fa';
}
protected $redirectTo = '/home'.$lang;
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
// there is some other methods in here
}
As I said, php doesn't let me to do this ^. How can I do that?
EDIT: I cannot put that if statement into __construct()
method. Because setLocale()
hasn't been set yet and getLocale()
always return default language (which is fa
). Anyway I need to put that if statement out of __construct()
. Any suggestion?