neeraj/catalyst-starterkit-restapi
Composer 安装命令:
composer require neeraj/catalyst-starterkit-restapi
包简介
Laravel Starter Kit with Authentication and CRUD Repository
README 文档
README
A ready-to-use Laravel starter kit featuring authentication and a base CRUD repository. This package is designed to save time and effort by providing a robust foundation for any Laravel-based API application.
Features
Authentication
- JWT-based authentication for secure API token management.
Base CRUD Repository
- Centralized CRUD repository pattern to minimize code redundancy and enhance maintainability.
Image Uploads
- Handles image uploads and storage with automatic naming and folder organization.
- Supports image uploads for all CRUD features, with files saved according to the model ID.
API Ready
- Pre-configured routes and controller logic to quickly set up API endpoints.
Flexible Parameters
- No need to send empty arrays (e.g.,
[]) for parameters unless required. - Middleware adjusts functionality based on the presence of data in the parameters.
Installation
Install the package using Composer:
composer require neeraj/catalyst-starterkit-restapi
php artisan jwt:secret
php artisan migrate
Usage
Controllers
- Example
ProductControlleris provided with full CRUD functionality. - Extend the
CrudRepositoryto add logic for other models. - Ensure the image folder is updated dynamically using the
$foldervariable based on model requirements.
Routes
Pre-configured routes for authentication and product management:
// routes/api.php Route::apiResource('products', ProductController::class);
To update a product using a PUT request:
localhost:8000/api/products/1?_method=PUT
Requests
Custom request classes for validation:
StoreProductRequestUpdateProductRequest
Environment Variables
- Set pagination count with
PAGINATEin.env. - Modify as per your requirements.
Folder Structure
app/
├── Http/
│ ├── Controllers/
│ │ └── ProductController.php
│ ├── Requests/
│ │ ├── StoreProductRequest.php
│ │ └── UpdateProductRequest.php
├── Models/
│ └── Product.php
├── Repositories/
│ ├── BaseRepository.php
│ └── CrudRepository.php
Image Handling
- Images are stored in folders named according to the model ID.
- To allow for multiple images, use the
$filearray to specify fields for the images. - Dynamically change the
$foldervariable for different models.
CRUD Repository Overview
The CrudRepository implements a centralized pattern for managing CRUD operations, designed to work seamlessly with various models. Below is an explanation of its key methods and usage:
index
$this->interface->index(Model $model, $paginated, $folder, $files, $where, $whereNot, $search, $active, $verify, $relation);
- Fetches records from the database.
- Supports optional filters for
where,whereNot,search, and status (active,verify). - Handles relationships (
$relation) and dynamically includes image paths if$filesand$folderare provided.
getById
$this->interface->getById(Model $model, $id, $folder, $files, $where, $whereNot, $search, $active, $verify, $relation);
- Fetches a single record by ID.
- Includes filters and dynamic file URLs, similar to the
indexmethod.
store
$this->interface->store(Model $model, $data, $request, $folder, $files, $modified_values, $hashing_values, $relation);
- Creates a new record in the database.
- Supports:
- Dynamic image storage.
- Relationships: Automatically creates related records for
hasOne,hasMany, andbelongsTorelations based on the$relationparameter.
update
$this->interface->update(Model $model, $data, $id, $request, $folder, $files, $modified_values, $hashing_values, $where, $whereNot, $search, $active, $verify, $relation);
- Updates an existing record by ID.
- Handles image updates, dynamic relationships, and field modifications.
delete
$this->interface->delete(Model $model, $folder, $id, $where, $whereNot, $search, $active, $verify, $relation);
- Deletes a record by ID, including related images stored in the specified folder.
verify / unverify
$this->interface->verify(Model $model, $id); $this->interface->unverify(Model $model, $id);
- Toggles the
verifiedstatus of a record.
getByDate / getBetweenDate
- Fetch records based on specific date criteria.
getMoreThan / getLessThan
- Fetch records where a field exceeds or is less than a specified value.
Contributing
Bug Fixes and Updates
- Identify and fix bugs, then push changes to the
bugbranch for review. - Collaboration is encouraged! Your contributions are a big help in improving the project.
- For new features, create branches with descriptive names, such as
feature-event-name. - For fixes, use branch names like
fix-issue-description.
We welcome collaboration and are excited to work with you to expand this project further! Please collaborate on GitHub and leave a star if you find this package useful.
Future Features
- Role and permission-based access control is in progress and will be updated soon.
- Improved relational data management, including:
- Nested CRUD operations for related models.
- Automated handling of pivot tables for many-to-many relationships.
- Default eager loading for optimized relational queries.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Niraj Bajagain (https://github.com/NeeRaj556)
neeraj/catalyst-starterkit-restapi 适用场景与选型建议
neeraj/catalyst-starterkit-restapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 neeraj/catalyst-starterkit-restapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 neeraj/catalyst-starterkit-restapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-22