简体   繁体   中英

Put javascript alert in Laravel model - Not able to alert message from Laravel Model

I want to alert a invalid message to the user from Laravel Model, I wrote the code but its not alerting. This piece of code works perfectly in simple PHP with wamp but this does not work with Laravel Model.

I Know this can be done using Ajax response and show the message in actual JS file instead of Model/Controller file but I want to know if there is a way to alert a JavaScript from Model itself instead of again AJAX call.

following is the function in my Model PHP where I am trying to alert a message:

public static function Login_Authenticator($request)
{
    if($ldapconn)
    {
        $ldapbind = @ldap_bind($ldapconn, $ldapuser, $ldappass) or  die("<script>alert('Invalid Credentials');</script>");
    }

}

I don't think die will work here try echo instead of die. Although, I feel this is bad practice because php should be used at the server side only. Try to add javascript in the view itself.

As you mention that you are getting the response in the controller then you should put a condition and redirect to view with an error message.

if (Your_condition) {
    return Redirect('/user/forgotpassword')
               ->with('fail', 'Missing required information, please request again.');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM