mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-31 04:55:50 +08:00
Added user-select input
This commit is contained in:
31
app/Http/Controllers/UserSearchController.php
Normal file
31
app/Http/Controllers/UserSearchController.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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) {
|
||||
$query->where('email', 'like', '%' . $search . '%')
|
||||
->orWhere('name', 'like', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$users = $query->get();
|
||||
return view('form.user-select-list', compact('users'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user