ArtiGrid
v1.6

Check for duplicate records when inserting

This example demonstrates how to prevent duplicate records when inserting data into the database. The checkDuplicateRecord() method ensures that no existing record has the same combination of the specified fields (in this case, title and description). If a duplicate is detected, the insertion will be blocked, helping maintain data integrity and avoid redundant entries.


<?php
    
    $grid = new ArtiGrid();
    $grid->table('gallery')
        ->required(false)
        ->validation_required('image')
        ->validation_required('title')
        ->validation_required('description')
        ->template('bootstrap5')
        ->fieldType('image', 'image')
        ->formFields([
            'image',
            'title',
            'description'
        ])
        ->checkDuplicateRecord([
            "title",
            "description"
        ]);
    echo $grid->render();
?>