App\Repositories\Recipe\EloquentRecipe::byPage PHP Метод

byPage() публичный Метод

Get paginated recipes.
public byPage ( integer $page = 1, integer $limit = 10 ) : Illuminate\Pagination\LengthAwarePaginator
$page integer Page number
$limit integer Number of recipes per page
Результат Illuminate\Pagination\LengthAwarePaginator
    public function byPage($page = 1, $limit = 10)
    {
        $recipes = $this->model->orderBy('name')->skip($limit * ($page - 1))->take($limit)->paginate($limit);
        return $recipes;
    }

Usage Example

Пример #1
0
 public function test_Should_GetRecipesByPage()
 {
     Factory::createList('App\\Models\\Recipe', [['name' => 'Recipe 1', 'description' => '', 'body' => ''], ['name' => 'Recipe 2', 'description' => '', 'body' => ''], ['name' => 'Recipe 3', 'description' => '', 'body' => ''], ['name' => 'Recipe 4', 'description' => '', 'body' => ''], ['name' => 'Recipe 5', 'description' => '', 'body' => '']]);
     $recipeRepository = new EloquentRecipe(new App\Models\Recipe());
     $foundRecipes = $recipeRepository->byPage();
     $this->assertCount(5, $foundRecipes->items());
 }
EloquentRecipe