1

I have products and software and movie belongs to product. I have created two validation requests and want to validate them like shown below.

public function store(StoreProductRequest $old_request)
{
    if ($old_request->type == 'MOVIE')
        $request = new StoreMovieRequest;
    else
        $request = new StoreSoftwareRequest;

    $request = $old_request;
    $request->validate();
}

Is there any way to achieve this in Laravel 5.1? I hope you understand my question.

1
  • could you elaborate more by showing your tables? and what your result should be? Commented Nov 3, 2015 at 17:12

1 Answer 1

1

One way of doing what you want to achieve is

public function store(StoreProductRequest $old_request){
    if ($old_request->type == 'MOVIE'){
    $request = new Requests\StoreMovieRequest;
    $this->validate($old_request, $request->rules());
    //validation passed for StoreMovieRequest
    }
    else {
    $request = new Requests\StoreSoftwareRequest;
    $this->validate($old_request, $request->rules());
    //validation passed for StoreSoftwareRequest
    }
}
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.