Skip to content

Commit

Permalink
feat: init ActionData
Browse files Browse the repository at this point in the history
  • Loading branch information
holiq committed Aug 21, 2024
0 parents commit 57dc2b9
Show file tree
Hide file tree
Showing 38 changed files with 11,424 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
vendor
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Simple way to use Actions and DTOs on your Laravel project

## Installation

```sh
composer require holiq/action-data
```

### Commands

#### Actions

```sh
php artisan make:action StorePostAction
```

#### DataTransferObjects

```sh
php artisan make:dto StorePostAction
```

### Example used

```php
// DTO
namespace App\DataTransferObjects;

use Holiq\ActionData\Foundation\DataTransferObject;

readonly class CategoryData extends DataTransferObject
{
public function __construct(
public string $name,
) {}
}

// Action
namespace App\Actions\Category;

use App\DataTransferObjects\CategoryData;
use App\Models\Category;
use Holiq\ActionData\Foundation\Action;

readonly class StoreCategoryAction extends Action
{
public function execute(CategoryData $data): void
{
Category::query()->create($data->toArray());
}
}

// Controller
namespace App\Http\Controllers\Category;

use App\Actions\Category\StoreCategoryAction;
use App\DataTransferObjects\CategoryData;
use App\Http\Controllers\Controller;
use App\Http\Requests\Category\StoreCategoryRequest;
use CuyZ\Valinor\Mapper\MappingError;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;

class StoreCategoryController extends Controller
{
/**
* @throws MappingError
*/
public function __invoke(StoreCategoryRequest $storeCategoryRequest): RedirectResponse
{
StoreCategoryAction::resolve()->execute(
data: CategoryData::resolve(data: $storeCategoryRequest->validated())
);

return Redirect::back();
}
}

```
63 changes: 63 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "holiq/action-data",
"description": "Laravel Package for generate Actions and DTOs on your projects",
"keywords": [
"holiq",
"action",
"datatransferobjects",
"dtos",
"laravel",
"laravelpackage"
],
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Holiq\\ActionData\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"authors": [
{
"name": "Holiq Ibrahim",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.2",
"illuminate/support": "^11.0",
"illuminate/console": "^11.0",
"illuminate/filesystem": "^11.0",
"illuminate/container": "^11.0",
"cuyz/valinor": "^1.0",
"spatie/php-cloneable": "^1.0"
},
"require-dev": {
"laravel/pint": "^v1.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.0"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
"providers": [
"Holiq\\ActionData\\ActionDataServiceProvider"
]
}
},
"scripts": {
"test": "vendor/bin/pest"
}
}
Loading

0 comments on commit 57dc2b9

Please sign in to comment.