2017 © Pedro Peláez
 

library laravel-interactions

Laravel package for interactions.

image

nasyrov/laravel-interactions

Laravel package for interactions.

  • Wednesday, April 4, 2018
  • by nasyrov
  • Repository
  • 0 Watchers
  • 4 Stars
  • 112 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 8 Versions
  • 3 % Grown

The README.md

Laravel Interactions

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Laravel package for interactions., (*2)

Requirements

Make sure all dependencies have been installed before moving on:, (*3)

Install

Pull the package via Composer:, (*4)

``` bash $ composer require nasyrov/laravel-interactions, (*5)


Register the service provider in `config/app.php`: ``` php 'providers' => [ ... Nasyrov\Laravel\Interactions\InteractionServiceProvider::class, ... ]

Usage

Let's generate a typical user registration flow with the use of interactions., (*6)

First, generate a RegisterUser interaction via the command:, (*7)

``` bash $ php artisan make:interaction RegisterUser, (*8)


The command above will create a new file `app/Interactions/RegisterUser.php`. Let's open the file and tailor it for our needs – create a new user: ``` php use App\User; use Illuminate\Http\Request; use Nasyrov\Laravel\Interactions\Contracts\Interaction; class RegisterUser implements Interaction { /** * Handle the interaction. * * @return mixed */ public function handle(Request $request) { return User::create([ 'name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password), ]); } }

Next, 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:, (*9)

``` php use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Nasyrov\Laravel\Interactions\CallsInteractions;, (*10)

class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, CallsInteractions, ValidatesRequests; }, (*11)


Finally, in the `UsersController` controller run the `RegisterUser` interaction and pass the request object: ``` php use App\Http\Controllers\Controller; use App\Interaction\RegisterUser; use Illuminate\Http\Request; class UsersController extends Controller { public function register(RegisterUserRequest $request) { return $this->interact(RegisterUser::class, [$request]); } }

Testing

bash $ composer lint $ composer test, (*12)

Security

If you discover any security related issues, please email inasyrov@ya.ru instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

26/03 2018