We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In my ProductRequest.php I have set this:
public function rules() { return [ 'name' => 'required|min:3|unique_with:products,category_id', 'price' =>'required' ]; }
And in my ProductsController.php I have this:
public function update(Product $product, ProductRequest $request) { $product->update($request->all()); return redirect('products'); }
But when I try to Update a field, like product's price, it gives me the message:
This combination of name, category id already exists.
Could someone help me?
The text was updated successfully, but these errors were encountered:
Define a separate ProductUpdateRequest.php:
ProductUpdateRequest.php
public function rules() { return [ 'name' => 'required|min:3, 'price' =>'required' ]; }
It would also be possible to specify one ID that should be ignored, but I think this is not possible with Laravel 5 Request objects.
Sorry, something went wrong.
Hi, I was playing with Request class, printing value of $this and this is what I've got:
public function rules() { switch($this->method()) { case 'POST': { return [ 'name' => 'required|min:3|unique_with:products,category_id', 'price' =>'required' ]; } case 'PATCH': { return [ 'name' => 'required|min:3|unique_with:products,category_id,'.$this->products->id, 'price' =>'required' ]; } }
No branches or pull requests
In my ProductRequest.php I have set this:
And in my ProductsController.php I have this:
But when I try to Update a field, like product's price, it gives me the message:
Could someone help me?
The text was updated successfully, but these errors were encountered: