我想知道是否有人可以帮助我。我有一个测试ftp连接的类。当我在我的控制器中运行代码时,它工作得很好,但是当我把代码放在它自己的类中时,它无法抛出任何东西。我的代码如下
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());
}
}
}
答案 0 :(得分:0)
我认为你要么需要命名这个类:
namespace App\Classes
或删除use Exception
并使用:
catch (Exception $e) {
return redirect()
->route('createbackup')
->withInput()
->withErrors($e->getMessage());
}