JeffreyWay / Laravel-Model-Validation

This Laravel package auto-validates a model on save.
https://packagist.org/packages/way/database
275 stars 54 forks source link

Laravel 5 compatibility #34

Open BadChoice opened 9 years ago

BadChoice commented 9 years ago

Is there planned an update for L5 compatibility?

BeingTomGreen commented 9 years ago

I can't speak for @JeffreyWay, but L5 offers form request validation which can simplify the process immensely.

BadChoice commented 9 years ago

Yea, form request validation looks great, but what if you are not using a form? Or even, you need to have another class for each model with its request validation, which means lots of more code

Or is there an easiest way?

BeingTomGreen commented 9 years ago

It would depend on your specific use case....

codebymark commented 9 years ago

In my use case I need model validation as I am building an API.

BeingTomGreen commented 9 years ago

Looking at the FormRequest class's response() method:

public function response(array $errors)
{
    if ($this->ajax() || $this->wantsJson())
    {
        return new JsonResponse($errors, 422);
    }

    return $this->redirector->to($this->getRedirectUrl())
                            ->withInput($this->except($this->dontFlash))
              ->withErrors($errors, $this->errorBag);
}

This leads me to believe they should work with API requests just fine, although I don't have time to check this at the minute.