diff --git a/src/Filters/PaginationDto.php b/src/Filters/PaginationDto.php new file mode 100644 index 000000000..310db73b2 --- /dev/null +++ b/src/Filters/PaginationDto.php @@ -0,0 +1,12 @@ +input('page.size') ?? $this->input('perPage')); + + if (is_array($this->input('page'))) { + $pageNumber = $this->input('page.number'); + } else { + $pageNumber = $this->input('page'); + } + + return new PaginationDto( + perPage: $perPage, + page: $pageNumber, + ); + } } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 436d53ce4..4dc40535e 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -550,7 +550,7 @@ public function index(RestifyRequest $request) * @var AbstractPaginator $paginator */ $paginator = RepositorySearchService::instance()->search($request, $this) - ->paginate($request->query('perPage') ?? static::$defaultPerPage); + ->paginate($request->pagination()->perPage ?? static::$defaultPerPage, page: $request->pagination()->page); $items = $this->indexCollection($request, $paginator->getCollection())->map(function ($value) { return static::resolveWith($value); diff --git a/src/Services/LoginService.php b/src/Services/LoginService.php index bf1a45aa9..5d2dd415f 100644 --- a/src/Services/LoginService.php +++ b/src/Services/LoginService.php @@ -4,7 +4,6 @@ use Binaryk\LaravelRestify\Events\UserLoggedIn; use Binaryk\LaravelRestify\Services\Concerns\AuthenticatesUsers; -use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Http\Request; class LoginService @@ -31,10 +30,6 @@ public function login(Request $request) } if ($this->attemptLogin($request)) { - if (($user = $this->guard()->user()) instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) { - return abort(401, 'User must verify email.'); - } - event(new UserLoggedIn($this->guard()->user())); return $this->guard()->user()->createToken('login'); diff --git a/tests/Controllers/Index/RepositoryIndexControllerTest.php b/tests/Controllers/Index/RepositoryIndexControllerTest.php index ba24c216c..814bd9885 100644 --- a/tests/Controllers/Index/RepositoryIndexControllerTest.php +++ b/tests/Controllers/Index/RepositoryIndexControllerTest.php @@ -43,6 +43,14 @@ public function it_can_paginate(): void ->etc() ); + $this->getJson(PostRepository::to(null, [ + 'page[size]' => 10, + ]))->assertJson( + fn (AssertableJson $json) => $json + ->count('data', 10) + ->etc() + ); + $this->getJson(PostRepository::to(null, [ 'perPage' => 10, 'page' => '2', @@ -51,6 +59,15 @@ public function it_can_paginate(): void ->count('data', 5) ->etc() ); + + $this->getJson(PostRepository::to(null, [ + 'page[size]' => 10, + 'page[number]' => 2, + ]))->assertJson( + fn (AssertableJson $json) => $json + ->count('data', 5) + ->etc() + ); } /** * @test */