santoshghimire/crud-generator

There is no license information available for the latest version (v1.0.1) of this package.

utility service package

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:project

pkg:composer/santoshghimire/crud-generator

v1.0.1 2026-01-23 15:31 UTC

This package is not auto-updated.

Last update: 2026-02-08 05:11:42 UTC


README

Laravel CRUD Generator is a developer-friendly package for generating clean, scalable, and microservice-ready CRUD modules using modern Laravel best practices.

It follows:

  • Repository Pattern
  • Service Layer Architecture
  • DTOs (Data Transfer Objects)
  • Data Builders
  • Swagger / OpenAPI Controllers
  • Modular structure (Authetication, Shoiiping, etc.) usefull in Nwidart package

This package is ideal for SaaS platforms, OpenApi-AutoSwagger Generate , Microservice, and API-first applications.

📦 Installation & Usage Guide

How to Install

Add Repository Source to composer.json

{
    "type": "vcs",
    "url": "https://gitlab.com/santosh112233/crud-generator",
    "packagist": false,
    "extra": {
        "secret": "auth.json"
    }
}
    composer require santoshghimire/crud-generator:1.0.1

Add Repository source to compose.json file

    {
        "type": "vcs",
        "url": "",
        "packagist": false,
        "extra": {
            "secret": "auth.json"
        }
    }

AND

    
     "require": {
         "santoshghimire/crud-generator": "dev-main"
     }

Make auth.json file at root of project

  • Go to gitlab => edit profile => Auth Token option and generate new one
  • git ignore this auth.json file for security, dont push this file in development
      {
          "gitlab-token": {
              "gitlab.com": "Add your personal access token  that you have created"
          }
      }
    

* `composer require  santoshghimire/crud-generator:dev-main` .
* Fix an error in package discovery if attempting to install both `` 

### Utility Service and examples

php artisan crud:generate Room --m --field=name:string,capacity:integer,price:decimal --module=MicroService


### Scofolding Generate Form This Pckage

Modules/ └── Order/

 ├── Http/
 │   ├── Controllers/
 │   │   └── OrderController.php
 │   └── Requests/
 │       └── OrderRequest.php
 ├── Models/
 │   └── Order.php
 ├── Repositories/
 │   ├── OrderRepository.php
 │   └── Interfaces/
 │       └── OrderRepositoryInterface.php
 ├── Services/
 │   └── OrderService.php
 ├── DTOs/
 │   └── OrderDTO.php
 ├── DataBuilders/
 │   └── OrderDataBuilder.php
 └── Database/
     └── Migrations/create_orders_table.php


### Controlller Generate From this Package
class TenantDetailController extends Controller
{
use ApiResponse;

public function __construct(
    public TenantDetailService $tenantDetailService
) {}

/**
 * @OA\Get(
 *     path="/api/tenantdetails",
 *     summary="Get tenant_details list",
 *     operationId="gettenant_details",
 *     tags={"tenantdetails"},
 *     @OA\Parameter(
 *         name="pagination",
 *         in="query",
 *         required=false,
 *         @OA\Schema(type="boolean", example=true)
 *     ),
 *     @OA\Parameter(
 *         name="X-Tenant",
 *         in="header",
 *         required=true,
 *         @OA\Schema(type="string")
 *     ),
 *     @OA\Response(
 *         response=200,
 *         description="TenantDetail list",
 *         @OA\JsonContent(
 *             @OA\Property(property="status", type="string"),
 *             @OA\Property(property="message", type="string"),
 *             @OA\Property(
 *                 property="data",
 *                 type="array",
 *                 @OA\Items(ref="#/components/schemas/TenantDetailResourceSchema")
 *             )
 *         )
 *     )
 * )
 */
public function index(Request $request)
{
    try {
        $relations = ['tenant.domain'];
        $data = $this->tenantDetailService->getAll($request, $relations);
    } catch (Exception $e) {
        Log::error($e->getMessage());
        return $this->errorResponse('Something went wrong', 500);
    }

    return $this->successResponse(
        TenantDetailResource::collection($data),
        'TenantDetail data retrieved successfully'
    );
}

/**
 * @OA\Post(
 *     path="/api/tenantdetails",
 *     summary="Create TenantDetail",
 *     operationId="storeTenantDetail",
 *     tags={"tenantdetails"},
 *     @OA\RequestBody(
 *         required=true,
 *         @OA\JsonContent(ref="#/components/schemas/TenantDetailCreateSchema")
 *     ),
 *     @OA\Response(
 *         response=201,
 *         description="TenantDetail created"
 *     )
 * )
 */
public function store(TenantDetailRequest $request)
{
    try {
        $dto = TenantDetailDataBuilder::getDtoData($request);
        $data = $this->tenantDetailService->store($dto);
    } catch (Exception $e) {
        dd($e);
        Log::error($e->getMessage());
        return $this->errorResponse('Something went wrong', 500);
    }

    return $this->successResponse(
        new TenantDetailResource($data),
        'TenantDetail created successfully',
        201
    );
}

/**
 * @OA\Get(
 *     path="/api/tenantdetails/{id}",
 *     summary="Get TenantDetail by ID",
 *     operationId="getTenantDetailById",
 *     tags={"tenantdetails"},
 *     @OA\Parameter(
 *         name="id",
 *         in="path",
 *         required=true,
 *         @OA\Schema(type="integer")
 *     ),
 *     @OA\Response(
 *         response=201,
 *         description="TenantDetail Fetch"
 *     )
 * )
 */
public function show($id)
{
    try {
        $data = $this->tenantDetailService->findById($id);
    } catch (Exception $e) {
        Log::error($e->getMessage());
        return $this->errorResponse('Something went wrong', 500);
    }

    return $this->successResponse(
        new TenantDetailResource($data),
        'TenantDetail retrieved successfully'
    );
}

/**
 * @OA\Patch(
 *     path="/api/tenantdetails/{id}",
 *     summary="Update TenantDetail",
 *     operationId="updateTenantDetail",
 *     tags={"tenantdetails"},
 *     @OA\Response(
 *         response=201,
 *         description="TenantDetail update"
 *     )
 * )
 */
public function update(TenantDetailRequest $request, $id)
{
    try {
        $dto = TenantDetailDataBuilder::getDtoData($request);
        $data = $this->tenantDetailService->update($dto, $id);
    } catch (Exception $e) {
        Log::error($e->getMessage());
        return $this->errorResponse('Something went wrong', 500);
    }

    return $this->successResponse(
        $data,
        'TenantDetail updated successfully'
    );
}

/**
 * @OA\Delete(
 *     path="/api/tenantdetails/{id}",
 *     summary="Delete TenantDetail",
 *     operationId="deleteTenantDetail",
 *     tags={"tenantdetails"},
 *     @OA\Response(
 *         response=204,
 *         description="TenantDetail Delete"
 *     )
 * )
 */
public function destroy($id)
{
    try {
        $this->tenantDetailService->delete($id);
    } catch (Exception $e) {
        Log::error($e->getMessage());
        return $this->errorResponse('Something went wrong', 500);
    }

    return $this->successResponse(null, 'tenant_details deleted successfully', 204);
}
/**
 * @OA\Patch(
 *     path="/api/tenantdetails/tenants/{id}/activate",
 *     summary="Activate tenant",
 *     tags={"Tenant"},
 *     @OA\Parameter(
 *         name="id",
 *         in="path",
 *         required=true,
 *         @OA\Schema(type="string")
 *     ),
 *     @OA\Response(
 *         response=200,
 *         description="Tenant activated successfully"
 *     )
 * )
 */

}


### Service layer Class
class TenantDetailService

{

public function __construct(
    public TenantDetailInterface $tenantDetailInterface,
) {}

public function getAll($request, $eagerLoadWithRelationData = [])
{
    try {
        $pagination = $request->boolean('pagination');
        $paginationNumber = $pagination ? 10 : null;

        return $this->tenantDetailInterface
            ->getAll(
                pagination: $pagination,
                paginate: $paginationNumber,
                withRelations: $eagerLoadWithRelationData
            );
    } catch (Exception $exception) {
        throw $exception;
    }
}
public function store(TenantDetailDTO $dto): TenantDetail
{
    try {
        DB::beginTransaction();

        $data = [
            'tenant_id' =>$tenant->id,
            'country_id' => $dto->country_id,
            'database_name' => $dto->database_name,
            'currency' => $dto->currency,
            'language' => $dto->language,
            'timezone' => $dto->timezone,
            'primary_email' => $dto->primary_email,
            'local_tin_number' => $dto->local_tin_number,
        ];

        $modelData = $this->tenantDetailInterface->create($data);
        $tenant->domain()->create([
            'domain' => $dto->domain,
        ]);
    } catch (Exception $exception) {
        DB::rollback();
        throw new Exception($exception);
    }
    DB::commit();

    return $modelData;
}

public function findById(int $id): TenantDetail
{
    try {
        $modelData = $this->tenantDetailInterface->getById($id);
    } catch (Exception $exception) {
        throw new Exception($exception);
    }

    return $modelData;
}

public function update(TenantDetailDTO $dto, $id)
{
    try {
        DB::beginTransaction();
        $data = [
            'country_id' => $dto->country_id,
            'currency' => $dto->currency,
            'language' => $dto->language,
            'timezone' => $dto->timezone,
            'primary_email' => $dto->primary_email,
            'local_tin_number' => $dto->local_tin_number,
        ];

        $modelData = $this->tenantDetailInterface->update($id, $data);
    } catch (Exception $exception) {
        DB::rollBack();
        throw new Exception($exception);
    }
    DB::commit();

    return $modelData;
}

public function delete($id): bool
{
    try {
        DB::beginTransaction();
        $this->tenantDetailInterface->delete($id);
    } catch (Exception $exception) {
        DB::rollBack();
        throw new Exception($exception);
    }
    DB::commit();

    return true;
}

}