You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
<?php
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\User;
|
|
use Illuminate\Http\Request;
|
|
use Spatie\QueryBuilder\AllowedFilter;
|
|
use Spatie\QueryBuilder\QueryBuilder;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
public function search(Request $request)
|
|
{
|
|
$limit = 20;
|
|
$userQ = User::query();
|
|
if ($request->filled('search')){
|
|
$userQ = $userQ->where(function($query) use ($request) {
|
|
$query->where('email', 'like', '%'.$request->search.'%')
|
|
->orWhere('username', 'like', '%'.$request->search.'%');
|
|
});
|
|
}
|
|
|
|
return $userQ->where('id', '!=', auth()->id())
|
|
->whereNotIn('id', request('_business_info')['info']['users']->keys())
|
|
->select('id', 'name', 'email', 'username')->take($limit)->get();
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$userQ = QueryBuilder::for(User::class)
|
|
->allowedFilters([
|
|
AllowedFilter::exact('id'),
|
|
]);
|
|
return $userQ->select('id', 'name', 'email', 'username')->get();
|
|
}
|
|
|
|
public function show($user)
|
|
{
|
|
return User::select('id', 'name', 'email', 'username')->findOrFail($user);
|
|
}
|
|
|
|
public function update(Request $request, string $user)
|
|
{
|
|
$user = User::findOrFail($user);
|
|
$user->update($request->all());
|
|
|
|
return $user;
|
|
}
|
|
|
|
public function setAvatar(Request $request, string $user)
|
|
{
|
|
$user = User::findOrFail($user);
|
|
if ($request->hasFile('avatar')) {
|
|
$user->saveAsAvatar($request->file('avatar'));
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
|
|
public function unSetAvatar(Request $request, string $user)
|
|
{
|
|
$user = User::findOrFail($user);
|
|
$user->deleteAvatar();
|
|
|
|
return $user;
|
|
}
|
|
}
|