PHPackages                             rmitesh/laravel-pantry - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rmitesh/laravel-pantry

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rmitesh/laravel-pantry
======================

To generate a Laravel class equipped with essential default features.

v1.0.7(2y ago)12531MITPHP

Since Sep 17Pushed 2y ago2 watchersCompare

[ Source](https://github.com/rmitesh/laravel-pantry)[ Packagist](https://packagist.org/packages/rmitesh/laravel-pantry)[ Docs](https://github.com/rmitesh/laravel-pantry)[ RSS](/packages/rmitesh-laravel-pantry/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (10)Used By (0)

Laravel Pantry
==============

[](#laravel-pantry)

You may know and worked with repository pattern in the Laravel.

Now, here I am going to introduce **Laravel Pantry** where you get all things in one place same as Food Pantry Shop.

[![laravel-pantry](https://private-user-images.githubusercontent.com/48554454/268523714-8b2976b7-04e6-495b-bb6c-a957bbfe0339.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1NzEyODEsIm5iZiI6MTc3NTU3MDk4MSwicGF0aCI6Ii80ODU1NDQ1NC8yNjg1MjM3MTQtOGIyOTc2YjctMDRlNi00OTViLWJiNmMtYTk1N2JiZmUwMzM5LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDE0MDk0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxNjk4ODg1OGFkMGMxMTExOGVkZDhmZmU5YjY0NzRkYzBlMTY5ZDIwZGNiM2ZkZTJkZTY0MWEyN2YxNzY4NzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0PuzCk5nv4yrt5EJppCmumZon1xcffZRSLwWH8N9x-o)](https://private-user-images.githubusercontent.com/48554454/268523714-8b2976b7-04e6-495b-bb6c-a957bbfe0339.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1NzEyODEsIm5iZiI6MTc3NTU3MDk4MSwicGF0aCI6Ii80ODU1NDQ1NC8yNjg1MjM3MTQtOGIyOTc2YjctMDRlNi00OTViLWJiNmMtYTk1N2JiZmUwMzM5LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDE0MDk0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxNjk4ODg1OGFkMGMxMTExOGVkZDhmZmU5YjY0NzRkYzBlMTY5ZDIwZGNiM2ZkZTJkZTY0MWEyN2YxNzY4NzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0PuzCk5nv4yrt5EJppCmumZon1xcffZRSLwWH8N9x-o)

[![Latest Stable Version](https://camo.githubusercontent.com/49334b0057f3ccd691afb7861c82f8781736977aa5934ee54e597916547a1b83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726d69746573682f6c61726176656c2d70616e7472792e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/rmitesh/laravel-pantry)[![Total Downloads](https://camo.githubusercontent.com/1b84fcf69c83f3db786fadbe7ace189879a2c50ff1d30c9b6ce7ed4516c964d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726d69746573682f6c61726176656c2d70616e7472792e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/rmitesh/laravel-pantry)[![Laravel v10.x](https://camo.githubusercontent.com/bfea501efe5759f52cfebee79ebb907199c9e88ae0bd65948d40ba67a1ad73fa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d7631302e782d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://laravel.com)[![PHP 8.1](https://camo.githubusercontent.com/f828b436a9f10bce9f30864883ab5b07c5f9bd5e21bf275312ad61f37dedce3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://php.net)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require rmitesh/laravel-pantry
```

### Create a new Pantry

[](#create-a-new-pantry)

To create a new Pantry class

```
php artisan make:pantry Food
```

> Based on the Pantry class name, automatically consider model name will be same as Pantry class.

Or you want to generate for specific model.

```
php artisan make:pantry Food --model=FoodItem
```

It will create `FoodPantry` class inside the `app/Pantries` directory. and `Food` is model class name.

So, final directory structure will look like this.

```
|── app
    └── Http
        └── Controllers
            └── FoodController.php
    └── Models
        └── Food.php
    └── Pantries
        └── FoodPantry.php

```

How to use
----------

[](#how-to-use)

In your `FoodController` add `__construct` function.

```
use App\Pantries\FoodPantry;

class FoodController extends Controller
{
	public function __construct(
	    protected FoodPantry $foodPantry
	) {}
}
```

OR

```
use App\Pantries\FoodPantry;

class FoodController extends Controller
{
	/**
	 * @var FoodPantry
	 */
	protected $foodPantry;

	public function __construct(FoodPantry $foodPantry) {
		$this->foodPantry = $foodPantry;
	}
}
```

Available Methods
-----------------

[](#available-methods)

### get()

[](#get)

To fetch single record.

```
$food = $this->foodPantry->get($record);
```

ArgumentValue$recordIt accepts model ID ( `Illuminate\Database\Eloquent\Model`, `string`, `id` )$columnsColumn names in array format, by default it will be `['*']`$relationshipsIt's Optional, You can pass relationship arguments in array. see [relationships](#fetch-data-with-relationships) examples> It will also works with Route Model Binding.

It will return eloquent class on record found, else it will throw `404 | Not found`.

### getAll()

[](#getall)

To fetch multiple records.

```
$foods = $this->foodPantry->getAll([
	// your column name, default '*',
	// conditions,
	// relationships
]);
```

With conditions, it's an optional parameter.

```
$foods = $this->foodPantry->getAll(
	conditions: [
		['where', 'status', true ],
		['whereHas', 'relationshipName' ],
	]
);
```

With relationships, it's an optional parameter. More details, check [Fetch data with relationships](#fetch-data-with-relationships).

```
$foods = $this->foodPantry->getAll([
	'id', 'name', 'created_at'
], [
	'with' => 'relationshipName',
]);
```

ArgumentValue$columnsColumn names in array format, by default it will be `['*']`$conditionsIt's Optional, You can add conditions, by default it will be empty array.$relationshipsIt's Optional, You can pass relationship arguments in array. see [relationships](#fetch-data-with-relationships) examplesAs a return it will give collection.

### paginate()

[](#paginate)

To fetch records with pagination.

To use `paginate()` method, you have to use `Rmitesh\LaravelPantry\Pantries\Concerns\HasPagination`.

```
use Rmitesh\LaravelPantry\Pantries\Concerns\HasPagination;

class FoodPantry extends Pantry
{
	use HasPagination; // add this in your Pantry class
}
```

For change per page records limit, you can override the `$perPageRecordLenght` in your Pantry class.

```
protected static ?int $perPageRecordLenght = 20;
```

> By default `$perPageRecordLenght` value set is `20` and that is enough for per page records.

```
$foods = $this->foodPantry->paginate([
		// your column name, default '*'
]);
```

Or with relationships

```
$foods = $this->foodPantry->paginate([
		// your column name, default '*'
], [
    'with' => 'ingredients',
]);
```

As a return it will give `Illuminate\Pagination\LengthAwarePaginator` collection.

### store()

[](#store)

To store data in table.

You need to just pass the array data.

```
$food = $this->foodPantry->store($request->validated());
```

ArgumentValue$dataArray key-value pairAs a return it will give created model instance.

### update()

[](#update)

To update data in table.

```
$food = $this->foodPantry->update($key, $request->validated());
```

ArgumentValue$keyIt accepts record ID ( `Illuminate\Database\Eloquent\Model`, `string`, `id` )$dataArray key-value pairAs a return it will give updated model instance.

### destroy()

[](#destroy)

To delete single record.

```
$food = $this->foodPantry->destroy($key);
```

ArgumentValue$keyIt accepts record ID ( `Illuminate\Database\Eloquent\Model`, `string`, `id` )As a return true on record deleted, false on failure.

### destroyAll()

[](#destroyall)

To delete multiple records at once.

```
$food = $this->foodPantry->destroyAll($ids);
```

ArgumentValue$idsIt accepts record ID in array or `Illuminate\Support\Collection` formatAs a return true on record deleted, false on failure.

### Fetch data with relationships.

[](#fetch-data-with-relationships)

To add relationships, you can pass in array format.

Let's take an example, One `Food` has many `ingredients`. So, to fetch `Food` records along with their `Ingredients`.

```
$foods = $this->foodPantry->getAll(
    relationships: [
        'with' => 'ingredients',
    ]
);
```

> For relationships, as key it should be relationship name like `with`, `withWhereHas`, `whereHas`, `withCount`, `whereBelongsTo` and so on.

Moreover, if you want to add `Closure` function then

```
use Illuminate\Database\Eloquent\Builder;

$foods = $this->foodPantry->getAll(
    relationships: [
        'with' => [
        	'ingredients',
        	function ( Builder $query ) {
	        	// your conditions
	        }
        ],
    ]
);
```

Or if you have multiple relationships then,

```
use Illuminate\Database\Eloquent\Builder;

$foods = $this->foodPantry->getAll(
    relationships: [
        'with' => [
        	[
        		'ingredients' => function ( Builder $query ) {
		        	// your conditions
		        },
        	],
        	[
        		// second relationship ...
        	],
        ],
    ]
);
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Buy me a Coffee
---------------

[](#buy-me-a-coffee)

[ ![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/rmitesh)Credits
-------

[](#credits)

- [Mitesh Rathod](https://github.com/rmitesh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Recently: every ~14 days

Total

9

Last Release

911d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4253e63057bd768605e3195dd8a8d32c9d5d8cb99b1cfedbc496a1235921ccd4?d=identicon)[rmitesh](/maintainers/rmitesh)

---

Top Contributors

[![rmitesh](https://avatars.githubusercontent.com/u/48554454?v=4)](https://github.com/rmitesh "rmitesh (19 commits)")[![AcostaLm](https://avatars.githubusercontent.com/u/16061673?v=4)](https://github.com/AcostaLm "AcostaLm (2 commits)")

---

Tags

laravelpantryrepository-patternlaravelrepositoryrmiteshlaravel-pantry

### Embed Badge

![Health badge](/badges/rmitesh-laravel-pantry/health.svg)

```
[![Health](https://phpackages.com/badges/rmitesh-laravel-pantry/health.svg)](https://phpackages.com/packages/rmitesh-laravel-pantry)
```

###  Alternatives

[cybercog/laravel-paket

Composer personal web interface. Manage Laravel dependencies without switching to command line!

1753.3k](/packages/cybercog-laravel-paket)[amin3520/anar

:description

272.3k](/packages/amin3520-anar)[mckenziearts/laravel-command

A simple Laravel package to provide artisan new commands

321.2k](/packages/mckenziearts-laravel-command)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
