3 namespace BookStack\Users\Controllers;
5 use BookStack\Http\Controller;
6 use BookStack\Permissions\Permission;
7 use BookStack\Users\Models\User;
8 use Illuminate\Http\Request;
10 class UserSearchController extends Controller
13 * Search users in the system, with the response formatted
14 * for use in a select-style list.
16 public function forSelect(Request $request)
18 $hasPermission = !user()->isGuest() && (
19 userCan(Permission::UsersManage)
20 || userCan(Permission::RestrictionsManageOwn)
21 || userCan(Permission::RestrictionsManageAll)
24 if (!$hasPermission) {
25 $this->showPermissionError();
28 $search = $request->get('search', '');
29 $query = User::query()
30 ->orderBy('name', 'asc')
33 if (!empty($search)) {
34 $query->where('name', 'like', '%' . $search . '%');
37 return view('form.user-select-list', [
38 'users' => $query->get(),