1. Go to this page and download the library: Download visiarch/laravel-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
visiarch / laravel-service example snippets
namespace App\Services\Interfaces;
/**
* Interface PostServiceInterface
*
* This interface defines the methods for the PostService class.
*/
interface PostServiceInterface
{
//
}
namespace App\Services;
use App\Services\Interfaces\PostServiceInterface;
/**
* Class PostService
*
* @package App\Services
*/
class PostService implements PostServiceInterface
{
//
}
public function register(): void
{
//
$this->app->bind(
\App\Services\Interfaces\PostServiceInterface::class,
\App\Services\PostService::class
);
}
namespace App\Services;
/**
* Class PostService
*
* @package App\Services
*/
class PostService
{
//
}
namespace App\Services\Interfaces;
use App\Models\Post;
class PostService implements PostServiceInterface
{
public function store(array $data): Post;
}
namespace App\Services;
use App\Models\Post;
class PostService implements PostServiceInterface
{
public function store(array $data): Post
{
return Post::create($data);
}
}
namespace App\Services;
use App\Models\Post;
class PostService
{
public function store(array $data): Post
{
return Post::create($data);
}
}
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'));
}
}
bash
php artisan make:service PostService
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.