PHPackages                             david-chamling/laravel-api-crud - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. david-chamling/laravel-api-crud

ActiveLibrary[HTTP &amp; Networking](/categories/http)

david-chamling/laravel-api-crud
===============================

A complete Laravel API CRUD generator with model, controller, service, requests and resources scaffolding

v1.0.1(9mo ago)12351MITPHPPHP ^8.0

Since May 27Pushed 9mo agoCompare

[ Source](https://github.com/Wadangkaa/laravel-api-crud)[ Packagist](https://packagist.org/packages/david-chamling/laravel-api-crud)[ RSS](/packages/david-chamling-laravel-api-crud/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel API CRUD Generator – Fast, Flexible, and Extensible API Scaffolding
===========================================================================

[](#laravel-api-crud-generator--fast-flexible-and-extensible-api-scaffolding)

[![Laravel](https://camo.githubusercontent.com/5a580364ff3bd338370177402c5c050ff81a1933927e1e475c920c90850b38a3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/5a580364ff3bd338370177402c5c050ff81a1933927e1e475c920c90850b38a3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)[![PHP](https://camo.githubusercontent.com/d282cc3193faee11ee32307d0c4c9d809e8fafa4b3a8c12c6afbf35d4f7ec617/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/d282cc3193faee11ee32307d0c4c9d809e8fafa4b3a8c12c6afbf35d4f7ec617/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![GitHub Repo stars](https://camo.githubusercontent.com/feacbc089b1f64389df759fb6171c77b0370a09349f26ef15780ab2c25264ff8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f776164616e676b61612f6c61726176656c2d6170692d637275643f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/feacbc089b1f64389df759fb6171c77b0370a09349f26ef15780ab2c25264ff8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f776164616e676b61612f6c61726176656c2d6170692d637275643f7374796c653d666f722d7468652d6261646765)

A powerful Laravel package that generates complete CRUD API scaffolding with a single Artisan command.

🚀 Features
----------

[](#-features)

- 🔧 Single-command CRUD scaffolding
- 🧩 Built-in lifecycle hooks (before/after store/update)
- 🚪 Custom route macros
- 🔍 Advanced search and filtering
- 📄 Pagination support
- 🛡️ Request validation
- 🎯 Resource transformation
- 👤 Automatic user tracking (created\_by / updated\_by)
- ⚙️ Customizable stubs

✅ Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9.x

📚 Learn by Example
------------------

[](#-learn-by-example)

Want to see it in action? Check out this step-by-step guide where we build a complete Blog API using this package:

👉 **[Read the full step-by-step tutorial on Medium](https://medium.com/@davidrai441/building-a-complete-blog-api-with-laravel-api-crud-generator-7349f46f046e)**

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require david-chamling/laravel-api-crud
```

(Optional) Publish stub files for customization:

```
php artisan vendor:publish --tag=crud-stubs
```

---

⚡ Basic Usage
-------------

[](#-basic-usage)

Generate full CRUD scaffolding for a model:

```
php artisan make:crud Product
```

This will generate:

- Controller
- Service class
- Form requests
- API resource
- Model
- Migration
- Routes

Define routes in your `routes/api.php`:

```
Route::crudResource('products', ProductController::class);
```

> ✅ Note: The `crudResource()` macro is automatically registered by the package.

---

🔒 Request Validation
--------------------

[](#-request-validation)

For security and data integrity, **you must define complete validation rules** in your generated request classes.

> ⚠️ **Important:** This CRUD system **only uses validated data**. If you forget to define rules in your request classes, fields like `name`, `price`, etc., will be empty or missing from your controller — even if you pass them in the request.

Define validation rules in your generated request classes:

```
// StoreProductRequest.php

public function rules(): array
{
    return [
        'name' => 'required|string|max:255',
        'price' => 'required|numeric|min:0',
        'category_id' => 'required|exists:categories,id'
    ];
}
```

---

🧩 Model Configuration
---------------------

[](#-model-configuration)

Ensure your model’s `$fillable` property includes all the fields:

```
// Product.php

protected $fillable = [
    'name',
    'price',
    'category_id',
    // Add additional fields here
];
```

---

📘 Generated Endpoints
---------------------

[](#-generated-endpoints)

MethodEndpointDescriptionGET/productsPaginated listGET/products/allGet all recordsGET/products/countCount total itemsGET/products/{id}Get single recordPOST/productsCreate new recordPUT/products/{id}Update recordDELETE/products/{id}Delete recordGET/products/featuredCustom endpoint---

🔍 Advanced Query Parameters
---------------------------

[](#-advanced-query-parameters)

Customize search, filters, and pagination in your controller:

```
protected array $searchableColumns = ['name', 'description'];
protected array $searchableRelations = ['category' => ['name']];
protected int $paginationNumber = 15;
```

Examples:

```
GET /products?search=keyboard
GET /products?filter[status]=active
GET /products?sort_by=price&sort_order=desc
GET /products?with=category&fields=id,name
GET /products?per_page=20&page=2

```

---

🪝 Lifecycle Hooks
-----------------

[](#-lifecycle-hooks)

Override lifecycle hooks in your custom CRUD service:

```
public function beforeStore(array $data, Request $request): array
{
    $data['slug'] = Str::slug($data['name']);
    return $data;
}

public function afterStore(Model $model, Request $request): void
{
    // sending Notification, Sms, Creating logs, Storing into relational table
    // example:
    ActivityLog::create([
        'user_id' => $request->user()->id,
        'action' => 'store',
        'model_id' => $model->id,
        'changes' => $model->getChanges(),
    ]);

    if ($model->wasChanged('status')) {
        Notification::send(
            $model->assignedUsers,
            new StatusUpdatedNotification($model)
        );
    }
}
```

---

🔁 API Responses
---------------

[](#-api-responses)

Use the built-in response helper for consistency:

```
use DavidChamling\LaravelApiCrud\Utilities\ApiResponse;

return ApiResponse::success($data);         // 200 OK
return ApiResponse::created($newModel);     // 201 Created
return ApiResponse::error('Something went wrong'); // 400/500 Error
return ApiResponse::validationError($errors);      // 422 Unprocessable
```

---

🧱 Customization
---------------

[](#-customization)

After publishing stubs, you can customize all generated files:

```
stubs/crud-controller/
├── controller.stub
├── model.stub
├── service.stub
├── store-request.stub
├── update-request.stub
├── resource.stub

```

Modify these to fit your code style or architecture.

---

💡 Example Controller
--------------------

[](#-example-controller)

```
use DavidChamling\LaravelApiCrud\Controllers\CrudController;
use DavidChamling\LaravelApiCrud\Utilities\ApiResponse;

class ProductController extends CrudController
{
    protected array $searchableColumns = ['name', 'sku'];
    protected array $searchableRelations = [
        'category' => ['name'],
        'manufacturer' => ['name'],
    ];

    public function __construct()
    {
        parent::__construct(
            model: Product::class,
            storeRequest: StoreProductRequest::class,
            updateRequest: UpdateProductRequest::class,
            simpleResource: ProductResource::class,
            detailedResource: ProductDetailResource::class,
            serviceClass: ProductCrudService::class
        );
    }

    public function featured()
    {
        $products = $this->model::featured()->get();
        return ApiResponse::success(ProductResource::collection($products));
    }
}
```

---

🛠️ Support
----------

[](#️-support)

Having issues or suggestions? Open an issue on GitHub:

👉 [GitHub Repository](https://github.com/wadangkaa/laravel-api-crud)

---

📝 License
---------

[](#-license)

MIT Licensed. See [LICENSE](https://opensource.org/licenses/MIT).

---

🤝 Contributing
--------------

[](#-contributing)

Pull requests and suggestions are welcome! Feel free to open issues for bugs or enhancements.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance57

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~61 days

Total

2

Last Release

287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d3c3ebc6d2e8552fc16ea865d4d3e8fdc325245828803cdf529a3669419a2bd?d=identicon)[Wadangkaa](/maintainers/Wadangkaa)

---

Top Contributors

[![Wadangkaa](https://avatars.githubusercontent.com/u/103678376?v=4)](https://github.com/Wadangkaa "Wadangkaa (8 commits)")

---

Tags

apilaravelrestscaffoldinggeneratorcrudcontroller

### Embed Badge

![Health badge](/badges/david-chamling-laravel-api-crud/health.svg)

```
[![Health](https://phpackages.com/badges/david-chamling-laravel-api-crud/health.svg)](https://phpackages.com/packages/david-chamling-laravel-api-crud)
```

###  Alternatives

[binaryk/laravel-restify

Laravel REST API helpers

651399.1k](/packages/binaryk-laravel-restify)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[mrdebug/crudgen

Create a Laravel Crud in a few seconds

31826.8k](/packages/mrdebug-crudgen)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[tomatophp/filament-api

Generate APIs from your filament resource using single line of code

507.1k1](/packages/tomatophp-filament-api)[sdv/laravel-endpoint

Laravel Endpoint is a CRUD REST API package for Laravel.

1118.8k](/packages/sdv-laravel-endpoint)

PHPackages © 2026

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