I'm trying to make things more simple in my Laravel application. Therefore I'm wondering how's it possible to NOT redirect the Client if one of my function returns true and how to redirect if it is a string (not true).
So let's say I have a function like this:
public function returnText() {
$r = rand(1,100);
if ($r > 50)
{
$redir = true;
}
else
{
$redir = 'http://google.com';
}
return $redir;
}
What I want within my Laravel's controller's function is to redirect the user if the result is an URL and don't redirect if it's simply 'true' (or anything basically it doesn't matter if I return true or something else).
Now I can obviously do that with a few lines but I'd like to optimize it only to take 1 max 2 lines.
public function redi() {
return redirect(CustomFunction::returnText());
}
I've tried this approach but it obviously throws some error, because it can't understand 'true'.
Any ideas on how to achieve this with the least lines of code?
P.S.: using Laravel 5.5
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire