Hi, I need help regarding validation. I want to validate multiple columns

Suppose I am having 2 columns and one foreign ID in a table. The record should be unique. E.g. Record one Product name = abc product area = def user_id = 1 record two Product name = abc product area = def user_id = 2 these both are unique I want to add this validation in filament product resource page
1 Reply
marco.ferreira
marco.ferreira16mo ago
You can use a unique rule with the where clause: https://laravel.com/docs/10.x/validation#rule-unique something like this:
'product_name' => Rule::unique('products')->where(fn (Builder $query) => $query->where('product_area', request('product_area'))->where('user_id', request('user_id')))
'product_name' => Rule::unique('products')->where(fn (Builder $query) => $query->where('product_area', request('product_area'))->where('user_id', request('user_id')))
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Want results from more Discord servers?
Add your server