-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 57dc2b9
Showing
38 changed files
with
11,424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.