PHPackages                             kha333n/crudmodule - 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. [Admin Panels](/categories/admin)
4. /
5. kha333n/crudmodule

ActiveLibrary[Admin Panels](/categories/admin)

kha333n/crudmodule
==================

Basic CRUD Module for Laravel Models

v1.0.0(1y ago)17MITPHPPHP ^8.2

Since Jul 13Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

Laravel CRUD Module
===================

[](#laravel-crud-module)

This is a simple CRUD module for Laravel. It is a simple module that can be used to create, read, update, and delete records in a database.

It will help you implement basic CRUD operations in Laravel with faster speed and better efficiency.

Don't waste your time on repetitive basic tasks
-----------------------------------------------

[](#dont-waste-your-time-on-repetitive-basic-tasks)

#### It is extensible and customizable to fit your needs

[](#it-is-extensible-and-customizable-to-fit-your-needs)

Features
--------

[](#features)

- Create, Read, Update, and Delete records in a database
- Easier to implement validation and authorization rules
- Filtering and Sorting records
- Customizing listing records
- Extending functionality using Observers and Events
- Out-of-the-box API support

Index
-----

[](#index)

- [Installation](#installation)
- [Usage](#usage)
- [Using via API routes](#using-via-api-routes)
- [Using via Controller](#using-via-controller)
- [Adding validation rules](#adding-validation-rules)
- [Adding Authorization rules](#adding-authorization-rules)
- [Filtering &amp; Sorting](#filtering--sorting)
- [Listing Customization](#listing-customization)
- [Extending Functionality](#extending-functionality)
- [License](#license)
- [Contributing](#contributing)
- [About kha333n](#about-kha333n)

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

[](#installation)

You can install the package via composer:

```
composer require kha333n/crudmodule
```

Usage
-----

[](#usage)

Add `Crudable` trait and implement `CrudableInterface` in your model. And Implement required `crudable` methods in your model.

```
use Kha333n\Crudable\Crudable;

class YourModel extends Model implements CrudableInterface
{
    use Crudable;

    public function crudable(): array {
        return [
            'column1',
            'column2',
            '...'
        ];
    }
}
```

Using via API routes
--------------------

[](#using-via-api-routes)

For most of the usage you can use it via built-in API routes They provide full CRUD operations

API Routes Available:

- GET `/{model}` - List all records
- GET `/{model}/{id}` - Get single record
- POST `/{model}` - Create new record
- PUT `/{model}/{id}` - Update record
- DELETE `/{model}/{id}` - Delete record
- DELETE `/{model}/{id}/force` - Force delete record
- PATCH `/{model}/{id}` - Restore record

Example: Using `Book` model

- GET `/api/book`
- GET `/api/book/1`
- POST `/api/book`
- PUT `/api/book/1`
- DELETE `/api/book/1`
- DELETE `/api/book/1/force`
- PATCH `/api/book/1`

Listing Customizations
----------------------

[](#listing-customizations)

You can customize listing records by passing query parameters in url

Available query parameters:

- `withTrashed = true` OR `withTrashed = 1` - Include soft deleted records
- `onlyTrashed = true` OR `onlyTrashed = 1` - Only show soft deleted records **(overrides withTrashed)**
- `paginate = true` OR `paginate = 1` - Paginate records
- `perPage = 10` - Number of records per page

Example: Using `Book` model

### GET `/api/book?withTrashed=true&paginate=true&perPage=23`

[](#get-apibookwithtrashedtruepaginatetrueperpage23)

Filtering &amp; Sorting
-----------------------

[](#filtering--sorting)

You can filter and sort records bypassing query parameters in url We are using [Spatie Laravel Query Builder](https://spatie.be/docs/laravel-query-builder/v5/introduction) for this see Spatie guide for more details

Example: Using `Book` model

### GET `/api/book?filter[title]=abc&sort=created_at`

[](#get-apibookfiltertitleabcsortcreated_at)

Using via Controller
--------------------

[](#using-via-controller)

In case you want greater control over CRUD or want customized application flow, you can directly interact with the model repository.

```
// Create new record
$model = Book::getRepository()->create($request->all());

// Update record
$model->repository()->update($request->all());

// Delete record
$model->repository()->delete();

// Get all records
$models = Book::getRepository()->all();
//OR
$models = $model->repository()->all();

// force delete record
$model->repository()->forceDelete();
```

Adding validation rules
-----------------------

[](#adding-validation-rules)

In your model, you can add validation rules for each column.

If not provided, it will use default validation rules based on its cast.

If both are not defined, it will treat it as a string.

Default Rules:

- `string: sometimes|string|max:255`
- `integer: sometimes|integer`
- `float: sometimes|numeric`
- `boolean: sometimes|boolean`
- `date: sometimes|date`

```
// in YourModel.php add array

    public array $rules = [
        'column1' => 'required|string|min:3|max:255',
        'column2' => 'required|string',
        '...' => 'required|string',
    ];
```

Adding Authorization rules
--------------------------

[](#adding-authorization-rules)

In your model, you can add authorization rule for each column

implement `CrudableInterface` in your model

Implement all required methods in your model and in each method, add your authorization logic

Available method:

- `canViewAny(Model $model)`
- `canView(Model $model)`
- `canCreate(Model $model)`
- `canUpdate(Model $model)`
- `canDelete(Model $model)`
- `canForceDelete(Model $model)`
- `canRestore(Model $model)`

In case you require only a few of them. Use `CrudableAdapter` trait in your model and then only add required ones. All others will be allowed by default.

Example:

```
// Only can create implemented
class Book implements \kha333n\crudmodule\Contracts\CrudableInterface {
    use \kha333n\crudmodule\Traits\CrudableAdapter;
    use \kha333n\crudmodule\Traits\Crudable;

    public function crudable(): array {
        return [
            'column1',
            'column2',
            '...'
        ];
    }

    public function canCreate(\Illuminate\Database\Eloquent\Model $model): bool {
        return auth()->user()->hasRole('Author');
    }
}
```

Filtering &amp; Sorting
-----------------------

[](#filtering--sorting-1)

For filtering and sorting we are using [Spatie Laravel Query Builder](https://spatie.be/docs/laravel-query-builder/v5/introduction) package.

By default, it will allow all fillable columns for both filtering and sorting

If you want to modify them or add own filtering rules, implement filters OR sorts method in your model

```
// See spatie query builder package for rules
    public function filters()
    {
        return $this->getFillable();
    }

    public function sorts()
    {
        return $this->getFillable();
    }
```

Listing Customization
---------------------

[](#listing-customization)

By default `all` function returns all records in model. But you can customize them by passing `CurdConfiguration` class to it with custom configuration.

#### Configurations Available

[](#configurations-available)

- `withTrashed = false`
- `onlyTrashed = false`
- `paginate = false`
- `perPage = 10`

Example:

```
YourModel::getRepository()->all(new \kha333n\crudmodule\Structures\CrudConfiguration(
    withTrashed: true,
    onlyTrashed: true, // When onlyTrashed is true, it overrides, the withTrashed and only deleted record will show
    paginate: true,
    perPage: 23
))
```

Extending Functionality
-----------------------

[](#extending-functionality)

Functionality of CRUD can be extended by 2 methods

1. Using Observers If you need to add additional data, modify or change data while some operation is on going use Observers on your model. Like while creating a book via CRUD you want to add a generated book\_slug to it. You can use observer for it.
2. Using Events If you need to perform some additional tasks after some operation is done. Like sending an email after creating a book. You can use events for it. Events available:
    - `Created`
    - `Updated`
    - `Deleted`
    - `ForceDeleted`
    - `Restored`

Example: On `Book` model register event listeners in `EventsServiceProvider` like this

```
    protected $listen = [
        'BookCreated' => [
            BookCreatedListener::class,
        ],
        'BookUpdated' => [
            BookUpdatedListener::class,
        ],
        'BookDeleted' => [
            BookDeletedListener::class,
        ],
        'BookForceDeleted' => [
            BookForceDeletedListener::class,
        ],
        'BookRestored' => [
            BookRestoredListener::class,
        ],
    ];
```

```
// BookCreatedListener.php
class BookCreatedListener
{
    public function handle(object $event)
    {
        // $event will contain the model instance on which operation performed
        // Perform your task here
    }
}
```

License
-------

[](#license)

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

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

[](#contributing)

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

About kha333n
-------------

[](#about-kha333n)

[kha333n](https://kha333n.com) is a web developer and open-source contributor.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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

Unknown

Total

1

Last Release

667d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a892740559dde48b168b888bd6d859813fd3d79f5a7c95c67c379405ae3d285c?d=identicon)[kha333n](/maintainers/kha333n)

---

Top Contributors

[![2btechdev2](https://avatars.githubusercontent.com/u/139965118?v=4)](https://github.com/2btechdev2 "2btechdev2 (4 commits)")[![kha333n](https://avatars.githubusercontent.com/u/44539272?v=4)](https://github.com/kha333n "kha333n (4 commits)")

---

Tags

crudcrud-apicrud-operationcurd-starter-templatelaravellaravel-frameworklaravel-packagelaravelcrud

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kha333n-crudmodule/health.svg)

```
[![Health](https://phpackages.com/badges/kha333n-crudmodule/health.svg)](https://phpackages.com/packages/kha333n-crudmodule)
```

###  Alternatives

[filament/infolists

Easily add beautiful read-only infolists to any Livewire component.

1220.8M36](/packages/filament-infolists)[resma/filament-awin-theme

A modern, responsive, and customizable theme for FilamentPHP, designed to elevate your admin panel with a sleek interface and seamless user experience.

1714.6k](/packages/resma-filament-awin-theme)

PHPackages © 2026

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