No need to put in model. You can put it in the controller. I mean where you post your data.
Help understanding validation
Can someone please help me with my understanding of validation. I have tried to find the answer for this question but have not been able to as of yet and I am hoping all of you might have my answer.
Lets say i have two models with two tables.
-
Product::model
-
Price::model
-
products::table
-
prices::table
I have fields from both that are used in my crud for products in my eCommerce build. My forms run through my Product involving the following:
PRODUCT FIELDS: name manufacturer details description
PRICE FIELDS: price model sku upc quantity alt_details
My question is do i put the validation to use in my ProductController like this:
$this->validate($request, [
'name' => 'required',
'manufacturer' => 'required',
'price' => 'required',
'details' => 'required',
'quantity' => 'required'
]);
or do i need to split them up and put them in a combined request like CreateProductRequest or put them in their corresponding models?
Does the flow of data make then look like one combined model / controller determined by the relationships or are they separate and need to be addressed that way.
Any help understanding this would be helpful and thank you in advance.
Yes, I'm saying stay with a ProductController, but if there are a lot of fields to validate then I prefer to create a formRequest to contain that.
https://laravel.com/docs/5.3/validation#form-request-validation
Please or to participate in this conversation.