1. Go to this page and download the library: Download holiq/action-data 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/ */
holiq / action-data example snippets
// 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();
}
}
sh
php artisan make:action StorePostAction
sh
php artisan make:dto StorePostAction
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.