0

When validating a form with a request class you can manually validate the data using the validate() method but what do you return back I've tried return $this and return $this->errors but it just shows SQL integrity constraint duplicate entry which is correct but it doesn't show my form with the errors. When doing validation inside the controller you return the model and the errors but what do I return and set errors on validate method in the request class.

Request Class:

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Auth;

class ProductRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    protected $action;

    public function authorize()
    {
        if(Auth::check()) {
            return true;            
        }        
    }

    public function validate() {

        $v = \Validator::make(parent::all(), $this->rules());
        if ($v->passes()) return true;
        $this->errors = $v->messages();
        // tried returning $this; and $this->errors
        return false;         
    }

    public function all()
    {
        $data = parent::all();

        if( $data['slug'] === '') {
            // if the slug is blank, create one from title data
            $data['slug'] = str_slug( $data['title'], '-' );
        }

        return $data;
    }

    public function messages()
    {
    }

    public function rules() {
    }

}
1

1 Answer 1

1

your rule method is empty your not validating any thing the error you got is an SQL exception not a validation error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.