49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\AvatarUrl;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class FollowerController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$user = $request->user();
|
|
$perPage = 30;
|
|
|
|
// People who follow $user (user_id = $user being followed)
|
|
$followers = DB::table('user_followers as uf')
|
|
->join('users as u', 'u.id', '=', 'uf.follower_id')
|
|
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
|
->leftJoin('user_statistics as us', 'us.user_id', '=', 'u.id')
|
|
->where('uf.user_id', $user->id)
|
|
->whereNull('u.deleted_at')
|
|
->orderByDesc('uf.created_at')
|
|
->select([
|
|
'u.id', 'u.username', 'u.name',
|
|
'up.avatar_hash',
|
|
'us.uploads_count',
|
|
'uf.created_at as followed_at',
|
|
])
|
|
->paginate($perPage)
|
|
->withQueryString()
|
|
->through(fn ($row) => (object) [
|
|
'id' => $row->id,
|
|
'username' => $row->username,
|
|
'uname' => $row->username ?? $row->name,
|
|
'avatar_url' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 50),
|
|
'profile_url' => '/@' . strtolower((string) ($row->username ?? $row->id)),
|
|
'uploads' => $row->uploads_count ?? 0,
|
|
'followed_at' => $row->followed_at,
|
|
]);
|
|
|
|
return view('dashboard.followers', [
|
|
'followers' => $followers,
|
|
'page_title' => 'My Followers',
|
|
]);
|
|
}
|
|
}
|