(Update) Refactor HTTP Redirects

- Use global redirect() helper instead of facade
This commit is contained in:
HDVinnie
2018-02-16 14:07:24 -05:00
parent 9893abfbb5
commit 8a8f440781
46 changed files with 161 additions and 260 deletions
+5 -7
View File
@@ -14,10 +14,8 @@ namespace App\Http\Controllers;
use App\User;
use App\Follow;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use \Toastr;
class FollowController extends Controller
@@ -32,15 +30,15 @@ class FollowController extends Controller
public function follow(User $user)
{
if (Auth::user()->id == $user->id) {
return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error("Nice try, but sadly you can not follow yourself.", 'Error!', ['options']));
return redirect()->route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error("Nice try, but sadly you can not follow yourself.", 'Error!', ['options']));
} elseif (!Auth::user()->isFollowing($user->id)) {
// Create a new follow instance for the authenticated user
Auth::user()->follows()->create([
'target_id' => $user->id,
]);
return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::success('You are now following ' . $user->username, 'Success!', ['options']));
return redirect()->route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::success('You are now following ' . $user->username, 'Success!', ['options']));
} else {
return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error('You are already following this user', 'Error!', ['options']));
return redirect()->route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error('You are already following this user', 'Error!', ['options']));
}
}
@@ -56,9 +54,9 @@ class FollowController extends Controller
$follow = Auth::user()->follows()->where('target_id', $user->id)->first();
$follow->delete();
return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::success('You are no longer following ' . $user->username, 'Success!', ['options']));
return redirect()->route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::success('You are no longer following ' . $user->username, 'Success!', ['options']));
} else {
return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error('You are not following this user to begin with', 'Error!', ['options']));
return redirect()->route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::error('You are not following this user to begin with', 'Error!', ['options']));
}
}
}