Skip to content

Commit 306cd7a

Browse files
authored
Merge pull request #4337 from Roardom/playlist-last-added
(Update) Save timestamps of when torrents are added to playlists
2 parents 55a6b28 + 625f20f commit 306cd7a

File tree

6 files changed

+83
-9
lines changed

6 files changed

+83
-9
lines changed

Diff for: app/Http/Controllers/PlaylistController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public function show(Request $request, Playlist $playlist): \Illuminate\Contract
123123
$randomTorrent?->category?->movie_meta => Movie::find($randomTorrent->tmdb),
124124
default => null,
125125
},
126-
'torrents' => $torrents,
126+
'latestPlaylistTorrent' => $playlist->torrents()->orderByPivot('created_at', 'desc')->first(),
127+
'torrents' => $torrents,
127128
]);
128129
}
129130

Diff for: app/Models/Playlist.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
6767
*/
6868
public function torrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
6969
{
70-
return $this->belongsToMany(Torrent::class, 'playlist_torrents')->using(PlaylistTorrent::class)->withPivot('id');
70+
return $this->belongsToMany(Torrent::class, 'playlist_torrents')->using(PlaylistTorrent::class)->withPivot('id')->withTimestamps();
7171
}
7272

7373
/**

Diff for: app/Models/PlaylistTorrent.php

-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ class PlaylistTorrent extends Pivot
3636
/** @use HasFactory<\Database\Factories\PlaylistTorrentFactory> */
3737
use HasFactory;
3838

39-
/**
40-
* Indicates If The Model Should Be Timestamped.
41-
*
42-
* @var bool
43-
*/
44-
public $timestamps = false;
45-
4639
/**
4740
* Indicates if the IDs are auto-incrementing.
4841
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\DB;
20+
use Illuminate\Support\Facades\Schema;
21+
22+
return new class () extends Migration {
23+
/**
24+
* Run the migrations.
25+
*/
26+
public function up(): void
27+
{
28+
Schema::table('playlist_torrents', function (Blueprint $table): void {
29+
$table->timestamps();
30+
});
31+
32+
DB::table('playlist_torrents')
33+
->join('playlists', 'playlist_torrents.playlist_id', '=', 'playlists.id')
34+
->update([
35+
'playlist_torrents.created_at' => DB::raw('playlists.created_at'),
36+
'playlist_torrents.updated_at' => DB::raw('playlists.created_at'),
37+
]);
38+
}
39+
};

Diff for: lang/en/playlist.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
'title' => 'Title',
3737
'titles' => 'Titles',
3838
'update-success' => 'Your Playlist Has Successfully Been Updated!',
39+
'last-addition-at' => 'Last addition at',
3940
];

Diff for: resources/views/playlist/show.blade.php

+40
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,46 @@ class="form__button form__button--filled form__button--centered"
127127
</p>
128128
</div>
129129
</section>
130+
<section class="panelV2">
131+
<h2 class="panel__heading">{{ __('common.info') }}</h2>
132+
<dl class="key-value">
133+
<div class="key-value__group">
134+
<dt>{{ __('common.created_at') }}</dt>
135+
<dd>
136+
<time
137+
datetime="{{ $playlist->created_at }}"
138+
title="{{ $playlist->created_at }}"
139+
>
140+
{{ $playlist->created_at->diffForHumans() }}
141+
</time>
142+
</dd>
143+
</div>
144+
<div class="key-value__group">
145+
<dt>{{ __('torrent.updated_at') }}</dt>
146+
<dd>
147+
<time
148+
datetime="{{ $playlist->updated_at }}"
149+
title="{{ $playlist->updated_at }}"
150+
>
151+
{{ $playlist->updated_at->diffForHumans() }}
152+
</time>
153+
</dd>
154+
</div>
155+
@if ($latestPlaylistTorrent !== null)
156+
<div class="key-value__group">
157+
<dt>{{ __('playlist.last-addition-at') }}</dt>
158+
<dd>
159+
<time
160+
datetime="{{ $latestPlaylistTorrent->pivot->created_at }}"
161+
title="{{ $latestPlaylistTorrent->pivot->created_at }}"
162+
>
163+
{{ $latestPlaylistTorrent->pivot->created_at->diffForHumans() }}
164+
</time>
165+
</dd>
166+
</div>
167+
@endif
168+
</dl>
169+
</section>
130170
@endsection
131171

132172
@section('main')

0 commit comments

Comments
 (0)