-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Enums\ResponseStatus; | ||
use App\Http\Requests\SearchUsersRequest; | ||
use App\Models\User; | ||
use App\Traits\CommonTrait; | ||
use Inertia\Inertia; | ||
|
||
class UserController extends Controller | ||
{ | ||
use CommonTrait; | ||
|
||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index() | ||
{ | ||
// render page | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
{ | ||
// render page | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(User $user) | ||
{ | ||
// render page | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Search users | ||
*/ | ||
public function search(SearchUsersRequest $request) { | ||
$validated = $request->validated(); | ||
$search = $validated['search']; | ||
|
||
$users = User::where('last_name', 'like', "%{$search}%") | ||
->orWhere('first_name', 'like', "%{$search}%") | ||
->orWhere('email', 'like', "%{$search}%") | ||
->orWhere('id', 'like', "%{$search}%") | ||
->orWhereHas('libraryPasses', function($query) use ($search) { | ||
$query->where('barcode', 'like', "%{$search}%"); | ||
}) | ||
->get(); | ||
|
||
return $this->CommonResponse( | ||
ResponseStatus::success, | ||
'Search results', | ||
$users | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Models\User; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class SearchUsersRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
$user = auth()->user(); | ||
return $user->can('search', User::class); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'search' => 'required|string|max:255' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters