Download the PHP package rmitesh/laravel-pantry without Composer
On this page you can find all versions of the php package rmitesh/laravel-pantry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rmitesh/laravel-pantry
More information about rmitesh/laravel-pantry
Files in rmitesh/laravel-pantry
Package laravel-pantry
Short Description To generate a Laravel class equipped with essential default features.
License MIT
Homepage https://github.com/rmitesh/laravel-pantry
Informations about the package 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.
Installation
You can install the package via composer:
Create a new Pantry
To create a new Pantry class
Based on the Pantry class name, automatically consider model name will be same as Pantry class.
Or you want to generate for specific model.
It will create FoodPantry
class inside the app/Pantries
directory.
and Food
is model class name.
So, final directory structure will look like this.
How to use
In your FoodController
add __construct
function.
OR
Available Methods
get()
To fetch single record.
Argument | Value |
---|---|
$record | It accepts model ID ( Illuminate\Database\Eloquent\Model , string , id ) |
$columns | Column names in array format, by default it will be ['*'] |
$relationships | It's Optional, You can pass relationship arguments in array. see 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()
To fetch multiple records.
With conditions, it's an optional parameter.
With relationships, it's an optional parameter. More details, check Fetch data with relationships.
Argument | Value |
---|---|
$columns | Column names in array format, by default it will be ['*'] |
$conditions | It's Optional, You can add conditions, by default it will be empty array. |
$relationships | It's Optional, You can pass relationship arguments in array. see relationships examples |
As a return it will give collection.
paginate()
To fetch records with pagination.
To use paginate()
method, you have to use Rmitesh\LaravelPantry\Pantries\Concerns\HasPagination
.
For change per page records limit, you can override the $perPageRecordLenght
in your Pantry class.
By default
$perPageRecordLenght
value set is20
and that is enough for per page records.
Or with relationships
As a return it will give Illuminate\Pagination\LengthAwarePaginator
collection.
store()
To store data in table.
You need to just pass the array data.
Argument | Value |
---|---|
$data | Array key-value pair |
As a return it will give created model instance.
update()
To update data in table.
Argument | Value |
---|---|
$key | It accepts record ID ( Illuminate\Database\Eloquent\Model , string , id ) |
$data | Array key-value pair |
As a return it will give updated model instance.
destroy()
To delete single record.
Argument | Value |
---|---|
$key | It accepts record ID ( Illuminate\Database\Eloquent\Model , string , id ) |
As a return true on record deleted, false on failure.
destroyAll()
To delete multiple records at once.
Argument | Value |
---|---|
$ids | It accepts record ID in array or Illuminate\Support\Collection format |
As a return true on record deleted, false on failure.
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
.
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
Or if you have multiple relationships then,
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Buy me a Coffee

Credits
- Mitesh Rathod
- All Contributors
License
The MIT License (MIT). Please see License File for more information.