Repository navigation
Expand file tree
/
Copy pathUserSearchController.php
More file actions
41 lines (36 loc) · 1.59 KB
/
Copy pathUserSearchController.php
File metadata and controls
41 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Http\Requests\ListApiUserSearchRequest;
use App\Http\Resources\UserResource;
use App\Models\User;
use App\Queries\UserSearchQuery;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Http\JsonResponse;
final readonly class UserSearchController
{
/**
* The people matching a name or handle, as the web's search finds them, with whether the user follows each one and
* whether each one follows them. People the user muted or blocked, or who blocked them, are left out.
*
* Deprecated for the profile search, which finds organizations too: it stays for the apps that still call it.
*/
public function index(ListApiUserSearchRequest $request, #[CurrentUser] User $user, UserSearchQuery $search): JsonResponse
{
$users = new Collection($search->get($request->string('q')->value(), $user)->all());
return UserResource::collection($users->loadExists([
'followers as is_followed' => function (Builder|Relation $query) use ($user): void {
$query->whereKey($user->id);
},
'following as follows_you' => function (Builder|Relation $query) use ($user): void {
$query->whereKey($user->id);
},
]))->response()->withHeaders([
'Deprecation' => 'true',
'Link' => '<'.route('api-profile-search.index').'>; rel="successor-version"',
]);
}
}