mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-03 16:59:32 -05:00
Refactor TorrentController
This commit is contained in:
@@ -134,15 +134,14 @@ class TorrentController extends Controller
|
||||
* @param Torrent $torrent
|
||||
* @return Response
|
||||
*/
|
||||
public function Bookmark($id)
|
||||
public function bookmark($id)
|
||||
{
|
||||
$torrent = Torrent::withAnyStatus()->findOrFail($id);
|
||||
$bookmarks = Auth::user()->bookmarks();
|
||||
if ($bookmarks->where('torrent_id', '=', $torrent->id)->first() === null) {
|
||||
$bookmarks->attach($torrent->id);
|
||||
return back()->with(Toastr::success('Torrent Has Been Bookmarked Successfully!', 'Yay', ['options']));
|
||||
} else {
|
||||
if (Auth::user()->hasBookmarked($torrent->id)) {
|
||||
return back()->with(Toastr::error('Torrent has already been bookmarked.', 'Error', ['options']));
|
||||
} else {
|
||||
Auth::user()->bookmarks()->attach($torrent->id);
|
||||
return back()->with(Toastr::success('Torrent Has Been Bookmarked Successfully!', 'Yay', ['options']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -239,6 +239,10 @@ class User extends Authenticatable
|
||||
return $this->belongsToMany(\App\Torrent::class, 'bookmarks', 'user_id', 'torrent_id')->withTimeStamps();
|
||||
}
|
||||
|
||||
public function hasBookmarked($torrent_id) {
|
||||
return $this->bookmarks()->where('torrent_id', '=', $torrent_id)->first() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of follows for the user.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ Route::group(['middleware' => 'auth'], function () {
|
||||
|
||||
// Bookmarks
|
||||
Route::get('/bookmarks', 'BookmarkController@bookmarks')->name('bookmarks');
|
||||
Route::any('/torrents/bookmark/{id}', 'TorrentController@Bookmark')->name('bookmark');
|
||||
Route::any('/torrents/bookmark/{id}', 'TorrentController@bookmark')->name('bookmark');
|
||||
Route::any('/torrents/unbookmark/{id}', 'BookmarkController@unBookmark')->name('unbookmark');
|
||||
|
||||
// User/Torrent Report
|
||||
|
||||
Reference in New Issue
Block a user