khant-nyar / service-extender
Creating a service base crud quickly
v1.0.0
2025-02-22 11:03 UTC
Requires
- php: ^8.2
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.20
- orchestra/testbench: ^6.23|^7.0|^8.0|^9.0|^10.0
- pestphp/pest: ^1.23
- phpunit/phpunit: ^9.0
README
- ✅ Improved Type Safety – Helps with debugging and prevents invalid data types.
- ✅ IDE-Friendly Navigation – Ctrl+Click methods to jump to service class.
- ✅ Automatic Transactions – Prevents database inconsistencies.
- ✅ Logging Enabled – Tracks changes for debugging.
- ✅ Easily Extendable – New services can override methods as needed.
Installation
You can install the package via composer:
composer require khant-nyar/service-extender
Usage
/** * Example uses with UserService */ namespace App\Services; use App\Models\User; use KhantNyar\ServiceExtender\Services\EloquenceService; class UserService extends EloquenceService { protected static string $model = User::class; }
it will generate automacally for UserService::all(),find($id),create($data)
/** * Example uses in controller */ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Services\UserService; class UserController extends Controller { public function index() { return response()->json(UserService::all()); } public function show($id) { return response()->json(UserService::find((int) $id)); } public function store(Request $request) { $data = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|min:6' ]); return response()->json(UserService::create($data), 201); } public function update(Request $request, $id) { $data = $request->validate([ 'name' => 'sometimes|string|max:255', 'email' => 'sometimes|email|unique:users,email,' . $id, 'password' => 'sometimes|min:6' ]); return response()->json(UserService::update((int) $id, $data)); } public function destroy($id) { return response()->json(['success' => UserService::delete((int) $id)]); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email khantnyar.dev@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.