PHPackages                             pareshsoneri/rsp-crud-generator - 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. [API Development](/categories/api)
4. /
5. pareshsoneri/rsp-crud-generator

ActiveLibrary[API Development](/categories/api)

pareshsoneri/rsp-crud-generator
===============================

A Laravel package to generate API CRUD operations using the Repository-Service Pattern.

v1.0.0(1y ago)12MITPHPPHP ^8.1

Since Dec 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mrsoneri/rsp-crud-generator)[ Packagist](https://packagist.org/packages/pareshsoneri/rsp-crud-generator)[ RSS](/packages/pareshsoneri-rsp-crud-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

RS CRUD Maker
=============

[](#rs-crud-maker)

`pareshsoneri/rsp-crud-generator` is a Laravel package designed to automatically generate CRUD operations for API resources. It adheres to the Repository and Service design patterns to promote clean, maintainable, and scalable code.

With a single command, this package sets up controllers, requests, resources, services, and repositories, enabling efficient management of your application's architecture.You only need to register my provider, as it automatically binds your repository.

---

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

[](#installation)

### Step 1: Install the Package

[](#step-1-install-the-package)

Run the following command to install the package via Composer:

```
composer require pareshsoneri/rsp-crud-generator:dev-main
```

### Step 2: Add the Service Provider

[](#step-2-add-the-service-provider)

Include the service provider in the `providers` array of your `config/app.php` file:

```
'providers' => [
    // Other service providers...
    RSPCrud\Providers\RepositoryServiceProvider::class,
],
```

### Step 3: Clear Laravel Cache

[](#step-3-clear-laravel-cache)

Ensure all changes are loaded by clearing Laravel's cache:

```
php artisan optimize:clear
```

---

Usage
-----

[](#usage)

To generate the CRUD structure for a specific resource, use the following Artisan command:

```
php artisan make:rsp-crud {Resource}
```

Replace `{Resource}` with the name of the resource (e.g., `Product`).

### Example

[](#example)

To create a CRUD structure for the `Product` resource, run:

```
php artisan make:rsp-crud Product
```

### Generated Folder Structure

[](#generated-folder-structure)

Executing the command generates the following folder and file structure:

```
/app
    /Http
        /Controllers
            /ProductController.php
        /Requests
            /ProductRequest.php
        /Resources
            /ProductListingResource.php
            /ProductCreateResource.php
            /ProductShowResource.php
    /Services
        /ProductService.php
    /Repositories
        /Contract
            /ProductRepositoryInterface.php
        /Eloquent
            /ProductRepository.php

```

---

Magic Behind the Command
------------------------

[](#magic-behind-the-command)

### Database Schema Inspection

[](#database-schema-inspection)

When you run the command `php artisan make:rsp-crud User`, the package inspects the `users` table in your database, fetching all columns except `id` and timestamp fields like `created_at` and `updated_at`.

### Request Data Generation

[](#request-data-generation)

The command automatically generates a `{Resource}Request.php` file containing validation rules for `create` and `update` operations. These rules are dynamically created based on the fields in the database table.

### Route Generation

[](#route-generation)

The command automatically generates the route and adds it to the api.php file, like this: Route::resource('users', UserController::class);.

#### Example: UserRequest.php

[](#example-userrequestphp)

```
