Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/holiq/action-data
Simple way to use Actions and DTOs on your Laravel project
https://github.com/holiq/action-data
actions data-transfer-object dto laravel
Last synced: about 1 month ago
JSON representation
Simple way to use Actions and DTOs on your Laravel project
- Host: GitHub
- URL: https://github.com/holiq/action-data
- Owner: holiq
- Created: 2024-08-21T07:43:44.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-08-21T08:24:22.000Z (3 months ago)
- Last Synced: 2024-09-29T23:23:36.573Z (about 2 months ago)
- Topics: actions, data-transfer-object, dto, laravel
- Language: PHP
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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();
}
}```