{"id":20309186,"url":"https://github.com/nasyrov/laravel-interactions","last_synced_at":"2025-04-11T15:40:28.878Z","repository":{"id":57023919,"uuid":"94197658","full_name":"nasyrov/laravel-interactions","owner":"nasyrov","description":"Laravel package for interactions.","archived":false,"fork":false,"pushed_at":"2018-04-04T09:08:33.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T11:49:20.634Z","etag":null,"topics":["interactions","laravel","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nasyrov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-13T09:51:49.000Z","updated_at":"2020-07-01T17:49:23.000Z","dependencies_parsed_at":"2022-08-23T14:20:38.026Z","dependency_job_id":null,"html_url":"https://github.com/nasyrov/laravel-interactions","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-interactions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-interactions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-interactions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nasyrov%2Flaravel-interactions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nasyrov","download_url":"https://codeload.github.com/nasyrov/laravel-interactions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432868,"owners_count":21102458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interactions","laravel","laravel-package","php"],"created_at":"2024-11-14T17:26:06.114Z","updated_at":"2025-04-11T15:40:28.855Z","avatar_url":"https://github.com/nasyrov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Interactions\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nLaravel package for interactions.\n\n## Requirements\n\nMake sure all dependencies have been installed before moving on:\n\n* [PHP](http://php.net/manual/en/install.php) \u003e= 7.0\n* [Composer](https://getcomposer.org/download/)\n\n## Install\n\nPull the package via Composer:\n\n``` bash\n$ composer require nasyrov/laravel-interactions\n```\n\nRegister the service provider in `config/app.php`:\n\n``` php\n'providers' =\u003e [\n    ...\n    Nasyrov\\Laravel\\Interactions\\InteractionServiceProvider::class,\n    ...\n]\n```\n\n## Usage\n\nLet's generate a typical user registration flow with the use of interactions.\n\nFirst, generate a `RegisterUser` interaction via the command:\n\n``` bash\n$ php artisan make:interaction RegisterUser\n```\n\nThe command above will create a new file `app/Interactions/RegisterUser.php`.\nLet's open the file and tailor it for our needs – create a new user:\n\n``` php\nuse App\\User;\nuse Illuminate\\Http\\Request;\nuse Nasyrov\\Laravel\\Interactions\\Contracts\\Interaction;\n\nclass RegisterUser implements Interaction\n{\n    /**\n     * Handle the interaction.\n     *\n     * @return mixed\n     */\n    public function handle(Request $request)\n    {\n        return User::create([\n            'name' =\u003e $request-\u003ename,\n            'email' =\u003e $request-\u003eemail,\n            'password' =\u003e bcrypt($request-\u003epassword),\n        ]);\n    }\n}\n```\n\nNext, include the `CallsInteractions` trait into the base controller so we will be able to run the interactions in any other controller that extends the one:\n\n``` php\nuse Illuminate\\Foundation\\Bus\\DispatchesJobs;\nuse Illuminate\\Routing\\Controller as BaseController;\nuse Illuminate\\Foundation\\Validation\\ValidatesRequests;\nuse Illuminate\\Foundation\\Auth\\Access\\AuthorizesRequests;\nuse Nasyrov\\Laravel\\Interactions\\CallsInteractions;\n\nclass Controller extends BaseController\n{\n    use AuthorizesRequests, DispatchesJobs, CallsInteractions, ValidatesRequests;\n}\n```\n\nFinally, in the `UsersController` controller run the `RegisterUser` interaction and pass the request object:\n\n``` php\nuse App\\Http\\Controllers\\Controller;\nuse App\\Interaction\\RegisterUser;\nuse Illuminate\\Http\\Request;\n\nclass UsersController extends Controller\n{\n    public function register(RegisterUserRequest $request)\n    {\n        return $this-\u003einteract(RegisterUser::class, [$request]);\n    }\n}\n```\n\n## Testing\n\n``` bash\n$ composer lint\n$ composer test\n```\n\n## Security\n\nIf you discover any security related issues, please email inasyrov@ya.ru instead of using the issue tracker.\n\n## Credits\n\n- [Evgenii Nasyrov][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/nasyrov/laravel-interactions.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/nasyrov/laravel-interactions/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/nasyrov/laravel-interactions.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/nasyrov/laravel-interactions.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/nasyrov/laravel-interactions.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/nasyrov/laravel-interactions\n[link-travis]: https://travis-ci.org/nasyrov/laravel-interactions\n[link-scrutinizer]: https://scrutinizer-ci.com/g/nasyrov/laravel-interactions/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/nasyrov/laravel-interactions\n[link-downloads]: https://packagist.org/packages/nasyrov/laravel-interactions\n[link-author]: https://github.com/nasyrov\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasyrov%2Flaravel-interactions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnasyrov%2Flaravel-interactions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasyrov%2Flaravel-interactions/lists"}