laravel-enso / people

Person management dependency for Laravel Enso
MIT License
5 stars 6 forks source link

Bindings for Validations #9

Closed stotes closed 5 years ago

stotes commented 5 years ago

People no longer has an interface contract for implementing the bindings of the request. (https://github.com/laravel-enso/people/tree/9afd2df78e543c388bae95b57d3044471104a007/src/app/Contracts)

Documentation still advises to

bind your local implementations to the package's ValidatePersonRequest in your local AppServiceProvider

$this->app->bind(
    ValidatesPersonRequest::class, MyValidatePersonRequest::class
);

Contracts have since been removed

What is the suggested best practice and would it be possible to update the documentation?

aocneanu commented 5 years ago

in your AppServiceProvider.php

use App\Http\Requests\ValidatePersonStore as LocalPersonStore;
use LaravelEnso\Companies\app\Http\Requests\ValidatePersonStore;

public function boot()
{
    $this->bind(ValidatePersonStore::class, function() {
         return new LocalPersonStore;
    });
}

local ValidatePersonStore.php

use LaravelEnso\Companies\app\Http\Requests\ValidatePersonStore as EnsoPersonStore;

class ValidatePersonStore extends EnsoPersonStore
...

You should do the same for the Person model and set at least the right fillable property.

aocneanu commented 5 years ago

@gandesc please update the docs for people and company.

stotes commented 5 years ago
$this->bind(ValidatePersonStore::class, function() {
         return new LocalPersonStore;
    });

Thank you for the guidance. It might be worth mentioning in the documentation to bind the ValidatePersonUpdate class as well.

use LaravelEnso\People\app\Http\Requests\ValidatePersonStore;
use App\Http\Requests\ValidatePersonStoreRequest as LocalPersonStore;
use LaravelEnso\People\app\Http\Requests\ValidatePersonUpdate;
use App\Http\Requests\ValidatePersonUpdateRequest as LocalPersonUpdate;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->app->bind(ValidatePersonStore::class, function () {
            return new LocalPersonStore();
        });
        $this->app->bind(ValidatePersonUpdate::class, function () {
            return new LocalPersonUpdate();
        });
    }