Browse Source

Refactored to firstOrFail and removed redundant validation checks.

Zdravko Vajagic 5 years ago
parent
commit
49507a7da8
1 changed files with 1 additions and 5 deletions
  1. 1 5
      app/Http/Controllers/UsersController.php

+ 1 - 5
app/Http/Controllers/UsersController.php

@@ -20,11 +20,7 @@ class UsersController extends Controller {
         $this->validate($request, [
         $this->validate($request, [
             'username' => 'required'
             'username' => 'required'
         ]);
         ]);
-        $application = Application::where('username', $request->username)->with('server')->first();
-        if(!$application) {
-            $request->session()->flash('alert-error', 'User not found!');
-            return redirect('/users');
-        }
+        $application = Application::where('username', $request->username)->with('server')->firstOrFail();
         $ssh = New SSH($application->server->ip, $application->server->port);
         $ssh = New SSH($application->server->ip, $application->server->port);
         if(!$ssh->login($application->server->username, $application->server->password)) {
         if(!$ssh->login($application->server->username, $application->server->password)) {
             $request->session()->flash('alert-error', 'There was a problem with server connection.');
             $request->session()->flash('alert-error', 'There was a problem with server connection.');