dimanche 23 octobre 2016

Laravel Exception not being thrown outside controller

Im wondering if someone could help me out. I have a class which is testing for an ftp connection. when i run the code inside my controller it works perfectly, but when i put the code inside its own class, it fails to throw anything. my code is as follows

use Exception;

class Backup implements BackupContract
{

    public function testConnection($credentials)
    {
        try {
            $connection = @ftp_connect($credentials['host']);
            if (false === $connection) {
                throw new Exception('Cant connect.');
            }

            $logged_in = @ftp_login($connection, $credentials['username'], $credentials['password']);
            if (false === $logged_in) {
                throw new Exception('Credentials wrong.');
            }
            @ftp_close($connection);
        } catch (\Exception $e) {
            return redirect()->route('createbackup')->withInput()->withErrors($e->getMessage());
        }
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire