PHP code example of plin-code / laravel-clean-architecture
1. Go to this page and download the library: Download plin-code/laravel-clean-architecture 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/ */
plin-code / laravel-clean-architecture example snippets
if (! class_exists(\Illuminate\Console\Command::class)
|| ! class_exists(\App\Domain\Shared\BaseModel::class)) {
throw new RuntimeException(
'clean-architecture: autoloading does not resolve the application classes, '
. 'so the reflection based rules would pass silently. Run composer dump-autoload.'
);
}
class ProductsController extends Controller
{
public function __construct(
private CreateProductAction $createProductAction,
private ProductService $productService
) {}
public function store(CreateProductRequest $request): JsonResponse
{
$product = $this->createProductAction->execute($request);
return response()->json([
'data' => new ProductResource($product),
'message' => 'Product created successfully'
], 201);
}
}