A simple Laravel package to create service, using artisan commands
visiarch/laravel-service is a Laravel package for a simple laravel package to create service, using artisan commands.
It currently has 0 GitHub stars and 17 downloads on Packagist (latest version 1.0.0).
Install it with composer require visiarch/laravel-service.
Discover more Laravel packages by visiarch
or browse all Laravel packages to compare alternatives.
Last updated

A Simple Package to create services, using artisan commands in laravel.
This package extends the make: commands to help you easily create service classes in Laravel 9+.
A service is a component that is responsible for executing an application's business logic. This is a place to place logic that may be too complex or inappropriate to place in the controller.
composer require visiarch/laravel-service
Once it is installed, you can use any of the commands in your terminal.
Services are used to separate business logic from the controller, making the controller leaner and focused on handling HTTP requests and providing appropriate responses.
php artisan make:service {name} --i
php artisan make:service {name}
php artisan make:service PostService --i
app/Services/Interfaces/PostServiceInterface.php
<?php
namespace App\Services\Interfaces;
/**
* Interface PostServiceInterface
*
* This interface defines the methods for the PostService class.
*/
interface PostServiceInterface
{
//
}
app/Services/PostService.php
<?php
namespace App\Services;
use App\Services\Interfaces\PostServiceInterface;
/**
* Class PostService
*
* @package App\Services
*/
class PostService implements PostServiceInterface
{
//
}
app\Providers\AppServiceProvider
public function register(): void
{
//
$this->app->bind(
\App\Services\Interfaces\PostServiceInterface::class,
\App\Services\PostService::class
);
}
php artisan make:service PostService
app/Services/PostService.php
<?php
namespace App\Services;
/**
* Class PostService
*
* @package App\Services
*/
class PostService
{
//
}
<?php
namespace App\Services\Interfaces;
use App\Models\Post;
class PostService implements PostServiceInterface
{
public function store(array $data): Post;
}
<?php
namespace App\Services;
use App\Models\Post;
class PostService implements PostServiceInterface
{
public function store(array $data): Post
{
return Post::create($data);
}
}
<?php
namespace App\Services;
use App\Models\Post;
class PostService
{
public function store(array $data): Post
{
return Post::create($data);
}
}
<?php
namespace App\Services;
use App\Models\Post;
use App\Interfaces\PostServiceInterface;
use App\Http\Requests\PostRequest;
class PostController extends Controller
{
protected $postService;
public function __construct(PostServiceInterface $postService)
{
$this->postService = $postService;
}
public function store(PostRequest $request): RedirectResponse
{
$data = $request->validated();
$this->postService->store($data);
return redirect()->route('posts.index')->with('success', __('post created'));
}
}
Just change PostServiceInterface to PostService if you are implementing without interface
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
Why not star the github repo? I'd love the attention! Why not share the link for this repository on any social media? Spread the word!
Thanks! visiarch
The MIT License (MIT). Please see License File for more information.