mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-27 05:50:51 -05:00
(Update) Refactor HTTP Redirects
- Use global redirect() helper instead of facade
This commit is contained in:
@@ -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']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user