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());
}
}
}
I think you are either going to need to namespace the class:
namespace App\Classes
or remove the use Exception
and use:
catch (Exception $e) {
return redirect()
->route('createbackup')
->withInput()
->withErrors($e->getMessage());
}