2020-12-31 12:25:20 -05: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)) {
|
2021-01-01 12:49:48 -05:00
|
|
|
$query->where(function (Builder $query) use ($search) {
|
2020-12-31 12:25:20 -05:00
|
|
|
$query->where('email', 'like', '%' . $search . '%')
|
|
|
|
->orWhere('name', 'like', '%' . $search . '%');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$users = $query->get();
|
2021-06-26 11:23:15 -04:00
|
|
|
|
2021-08-22 08:15:58 -04:00
|
|
|
return view('form.user-select-list', compact('users'));
|
2020-12-31 12:25:20 -05:00
|
|
|
}
|
|
|
|
}
|