https://github.com/getsolaris/laravel-make-service
:rocket: Create a service layer for Laravel 5+
https://github.com/getsolaris/laravel-make-service
laravel php
Last synced: 3 months ago
JSON representation
:rocket: Create a service layer for Laravel 5+
- Host: GitHub
- URL: https://github.com/getsolaris/laravel-make-service
- Owner: getsolaris
- License: mit
- Created: 2018-10-16T17:03:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-06-30T04:05:06.000Z (9 months ago)
- Last Synced: 2026-01-16T13:36:45.122Z (3 months ago)
- Topics: laravel, php
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 81
- Watchers: 5
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Make Service
[](https://packagist.org/packages/getsolaris/laravel-make-service)
[](https://packagist.org/packages/getsolaris/laravel-make-service)
[](https://packagist.org/packages/getsolaris/laravel-make-service)
[](https://packagist.org/packages/getsolaris/laravel-make-service)
[](https://packagist.org/packages/getsolaris/laravel-make-service)
A Laravel package that provides an Artisan command to generate service classes, implementing the MVCS (Model-View-Controller-Service) pattern in your Laravel applications.
## Overview
This package simplifies the creation of service layer classes in Laravel applications. It helps you maintain clean architecture by separating business logic from controllers, making your code more maintainable, testable, and reusable.
## Requirements
- PHP 7.1 or higher
- Laravel 5.6.34 or higher (supports up to Laravel 12)
## Installation
Install the package via Composer:
```bash
composer require getsolaris/laravel-make-service --dev
```
The package will automatically register itself using Laravel's package discovery.
## Usage
### Basic Command Syntax
```bash
php artisan make:service {name} {--i : Create a service interface}
```
### Creating a Service Class
To create a simple service class:
```bash
php artisan make:service UserService
```
This will create a service class at `app/Services/UserService.php`:
```php
$data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
});
}
/**
* Update user information
*
* @param User $user
* @param array $data
* @return bool
*/
public function updateUser(User $user, array $data): bool
{
if (isset($data['password'])) {
$data['password'] = Hash::make($data['password']);
}
return $user->update($data);
}
/**
* Get user statistics
*
* @param User $user
* @return array
*/
public function getUserStatistics(User $user): array
{
return [
'posts_count' => $user->posts()->count(),
'comments_count' => $user->comments()->count(),
'last_login' => $user->last_login_at,
];
}
}
```
### Using Services in Controllers
```php
userService = $userService;
}
public function store(StoreUserRequest $request): JsonResponse
{
$user = $this->userService->createUser($request->validated());
return response()->json([
'message' => 'User created successfully',
'user' => $user
], 201);
}
public function update(UpdateUserRequest $request, User $user): JsonResponse
{
$this->userService->updateUser($user, $request->validated());
return response()->json([
'message' => 'User updated successfully',
'user' => $user->fresh()
]);
}
public function statistics(User $user): JsonResponse
{
$stats = $this->userService->getUserStatistics($user);
return response()->json($stats);
}
}
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## Support
If you discover any issues or have questions, please [create an issue](https://github.com/getsolaris/laravel-make-service/issues).
## Author
- **Solaris** - [getsolaris](https://github.com/getsolaris)
- Email: getsolaris.kr@gmail.com
## License
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).