laravel collection unique code example
Example 1: collection laravel filter
$collection = collect([1, 2, 3, 4]);
$filtered = $collection->filter(function ($value, $key) {
return $value > 2;
});
$filtered->all();
Example 2: add to collection laravel
$item = collect();
$item->push($product);
Example 3: laravel unique validation
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
}
Example 4: laravel rule unique where
'required|email|unique:company_users,email_address,NULL,id,company_id,' . $request->company_id
Example 5: laravel unique column except self
'required|unique:users,email,'.$this->id . ',user_id';