Thursday, 21 September 2023

laravel unique validation, except self , ignore self or current row

 public function rules(): array
    {
        return [
            'title' => [
                'required',
                Rule::unique(Category::class, 'title')->ignore($this->id, 'id'),
                'max:255'
            ],
            'slug' => [
                'required',
                Rule::unique(Category::class, 'slug')->ignore($this->id, 'id'),
                'max:255'
            ],
            'image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
        ];
    }

No comments:

Post a Comment

Laravel Export data to csv

 use Illuminate\Http\Response; // Define a function to export data to CSV function exportToCSV($exportData, $columns) {     $filename = ...