Skip to content

Commit

Permalink
feat: search for id or librarypass barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrinsieboy committed Jan 19, 2024
1 parent 4e1628a commit a07ca4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ public function search(SearchUsersRequest $request) {
$users = User::where('last_name', 'like', "%{$search}%")
->orWhere('first_name', 'like', "%{$search}%")
->orWhere('email', 'like', "%{$search}%")
->get();

->orWhere('id', 'like', "%{$search}%")
->orWhereHas('libraryPasses', function($query) use ($search) {
$query->where('barcode', 'like', "%{$search}%");
})
->get();

return $this->CommonResponse(
ResponseStatus::success,
Expand Down
7 changes: 6 additions & 1 deletion src/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
Expand All @@ -13,4 +13,9 @@ class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
protected $guarded = [];

public function libraryPasses(): HasOne
{
return $this->hasOne(LibraryPass::class);
}
}

0 comments on commit a07ca4a

Please sign in to comment.