2
It is possible within a Controller to return a javascript action and proceed with the controller script ?
Example:
Call to Login page:
<li><a href="javascript:" link="{{ route('login') }}" class="popup">logar</a></li>
$('.popup').click(function(ev){
var URL = $(this).attr("link");
window.open(URL,'janela', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
});
Controller
class testeController extends BaseController {
public function teste($process = null)
{
if ($process) {
return function();
}
echo '<script type="text/javascript">window.close()</script>';
if(Auth::check()){
$role = User::find(Auth::user()->id)->roles()->first();
return Redirect::to($role->name)->with('success', 'Logado com sucesso');
}else{
return Redirect::to('/')->with('warning', 'Não foi possível autenticá-lo, tente novamente mais tarde ou nos contate');
}
...
however javascript echo does not work inside the controller, only if I give a Return, and if I give a Return the rest of the controller function is not executed.
What is the best procedure in this case ?
Tentative1:
class testeController extends BaseController {
public function teste($process = null)
{
if ($process) {
return function();
}
Functions::jsController('close');
if(Auth::check()){
$role = User::find(Auth::user()->id)->roles()->first();
return Redirect::to($role->name)->with('success', 'Logado com sucesso');
}else{
return Redirect::to('/')->with('warning', 'Não foi possível autenticá-lo, tente novamente mais tarde ou nos contate');
}
...
public static function jsController($acao){
if($acao == 'close'){
return '<script type="text/javascript">window.close()</script>';
}
}
The best way to do this is with Ajax.
– Diego Souza