BookStack/app/Http/Controllers/UserSearchController.php

32 lines
863 B
PHP
Raw Normal View History

2021-01-01 01:25:20 +08:00
<?php
namespace BookStack\Http\Controllers;
use BookStack\Auth\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
class UserSearchController extends Controller
{
/**
* Search users in the system, with the response formatted
* for use in a select-style list.
*/
public function forSelect(Request $request)
{
$search = $request->get('search', '');
$query = User::query()->orderBy('name', 'desc')
->take(20);
if (!empty($search)) {
$query->where(function (Builder $query) use ($search) {
2021-01-01 01:25:20 +08:00
$query->where('email', 'like', '%' . $search . '%')
->orWhere('name', 'like', '%' . $search . '%');
});
}
$users = $query->get();
2021-01-01 01:27:23 +08:00
return view('components.user-select-list', compact('users'));
2021-01-01 01:25:20 +08:00
}
}