Hello Sir, When I try to update the product by clicking the update button without changing any info of the product, showing the error message below the 'slug' input field: "The slug has already been taken." Is it suitable to use the below validation code for updating a product? 'slug' => "required|unique:products"
I got the idea from a user comment in lesson 38 (i.e. Admin Add Coupons Expiry Date) and applied the idea to AdminEditCategoryComponent.php and AdminEditProductComponent.php. They work well. I share the partial code of the AdminEditProductComponent.php file as below: use Illuminate\Validation\Rule; protected function category_rules() { return [ 'name' => 'required', 'slug' => [ 'required', Rule::unique('categories')->ignore($this->category_id) ] ]; } public function updated($fields) { $this->validateOnly($fields, $this->category_rules()); } public function updateCategory() { $this->validate($this->category_rules()); $category = Category::find($this->category_id); $category->name = $this->name; $category->slug = $this->slug; $category->save(); session()->flash('message', 'Category has been updated successfullly!'); }
When I try to update the product by clicking the update button without changing any info of the product, showing the error message below the 'slug' input field: "The slug has already been taken." Is it suitable to use the below validation code for updating a product? 'slug' => "required|unique:products"
there is a problem of showing "The slug has already been taken" if I want to edit product details then I have to edit the slug. otherwise the problem is arising each time. anybody please help..........
Hi i have some problems in video 6-create product details. in details-component.blade.php i get this error. " Trying to get property 'image' of non-object (View: C:\xampp\htdocs\laravel8ecommerce esources\views\livewire\details-component.blade.php) " when i add {{$product->image}}" it occurs. Can anyone help me. Or can anyone give me the details-component.blade.php file code so that i can check the error... Please help!
@SafayetHossain.. might be you solve the issue but for others. i am suggesting the following code for validation. 'slug' => ['required', Rule::unique('products')->ignore($this->product_id,'id')], then conditionally pass the value in DB like below. $product->sell_price = (!$this->sell_price ? null : $this->sell_price); Hope it'll help to solve the issue.
if we just want to update the price or any input exept the newimage it doesnt work ...it just work if we change the image then we can update all others input ...why ???
@@SurfsideMedia i did it already ,i put "sometimes" instead of "required"...anyway it should be something else , i will find .....thanks for your reply
Sir, Add to cart button not working , I check all the code twice. Please mention places where I can do mistakes and I think something missed in here .wire:click.prevant="store({{$product->id}},'{{$product->name}}',{{$product->regular_price}}). Please help me sir!
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'newimage' in 'field list' (SQL: update `products` set `slug` = dafvab, `newimage` = 1618200388.jpg, `products`.`updated_at` = 2021-04-12 04:06:28 where `id` = 4) I dont know why I facing this problem........
best tutorials ever. keep up the good work, God bless you.
Thanks Surfside Media.
Hello Sir,
When I try to update the product by clicking the update button without changing any info of the product, showing the error message below the 'slug' input field:
"The slug has already been taken."
Is it suitable to use the below validation code for updating a product?
'slug' => "required|unique:products"
I got the idea from a user comment in lesson 38 (i.e. Admin Add Coupons Expiry Date)
and applied the idea to AdminEditCategoryComponent.php and AdminEditProductComponent.php.
They work well.
I share the partial code of the AdminEditProductComponent.php file as below:
use Illuminate\Validation\Rule;
protected function category_rules()
{
return [
'name' => 'required',
'slug' => [
'required',
Rule::unique('categories')->ignore($this->category_id)
]
];
}
public function updated($fields)
{
$this->validateOnly($fields, $this->category_rules());
}
public function updateCategory()
{
$this->validate($this->category_rules());
$category = Category::find($this->category_id);
$category->name = $this->name;
$category->slug = $this->slug;
$category->save();
session()->flash('message', 'Category has been updated successfullly!');
}
@@kitky Thank you so much for sharing!! An excellent way to "abbreviate" those lines.
@@kitky thanks very much
When I try to update the product by clicking the update button without changing any info of the product, showing the error message below the 'slug' input field:
"The slug has already been taken."
Is it suitable to use the below validation code for updating a product?
'slug' => "required|unique:products"
'slug' => ['required', Rule::unique('products')->ignore($this->product_id)],
when the category is select it just appears for a second and then gone. Can you give me a solution for it?
there is a problem of showing "The slug has already been taken" if I want to edit product details then I have to edit the slug. otherwise the problem is arising each time. anybody please help..........
Respect!!! The best content ever!!!
Hi i have some problems in video 6-create product details. in details-component.blade.php i get this error. " Trying to get property 'image' of non-object (View: C:\xampp\htdocs\laravel8ecommerce
esources\views\livewire\details-component.blade.php) " when i add {{$product->image}}" it occurs. Can anyone help me. Or can anyone give me the details-component.blade.php file code so that i can check the error... Please help!
When I am trying to update category then it shows slug has already been taken? how to solve this problem? pls help me.
Surfside Media, notice this comment!!! It's important.
@SafayetHossain.. might be you solve the issue but for others. i am suggesting the following code for validation.
'slug' => ['required', Rule::unique('products')->ignore($this->product_id,'id')],
then conditionally pass the value in DB like below.
$product->sell_price = (!$this->sell_price ? null : $this->sell_price);
Hope it'll help to solve the issue.
It gives me great pleasure.
thank you very much
if we just want to update the price or any input exept the newimage it doesnt work ...it just work if we change the image then we can update all others input ...why ???
Please remove required validation for newimage
@@SurfsideMedia i did it already ,i put "sometimes" instead of "required"...anyway it should be something else , i will find .....thanks for your reply
@@SurfsideMedia ok no validation at all for the image in the edit product and it works now..thank you sir
|unique:products in edit validation on slug does not work Suggestions
Sir, Add to cart button not working , I check all the code twice. Please mention places where I can do mistakes and I think something missed in here .wire:click.prevant="store({{$product->id}},'{{$product->name}}',{{$product->regular_price}}).
Please help me sir!
Spelling mistake in prevent, write like this, wire:click.prevent=""
I had the same problem, please anyone help me.
@@SurfsideMedia Sir, Spelling sahi krne ke bad bhi koi ferk nhi pda h. Mention places whee I can do mistakes.
try use style tag after main section, if you use it before main section
Very interesting
thanks alot sir was looking for that.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'newimage' in 'field list' (SQL: update `products` set `slug` = dafvab, `newimage` = 1618200388.jpg, `products`.`updated_at` = 2021-04-12 04:06:28 where `id` = 4)
I dont know why I facing this problem........
newimage is not a column name inside the products table, so please recheck your code. Watch my video again and match the code.
Creating default object from empty value
why you are not using required="required"?
easy to remove via inspect element
Thank you!
Thank you! I'm the first here! hahha
tnx
please make a verible products
and muti vender system
Sir , pagination CSS ka code bhi post kr dijiye please
github.com/surfsidemedia/Laravel-8-E-Commerce-Pages
solution for slug error: The slug has already taken
'slug' => ['required', Rule::unique('products')->ignore($this->product_id)],
don't work
@@bcsenior162 laravel 9
@@jorgeluiscch1576 I use laravel 9, tried of everything and nothing, in the crud categories is the same mistake
Duplicate code :) D.R.Y : Don't Repeat Yourself !