setModel

setModel(\GroceryCrud\Core\Model\ModelInterface $model);

By default GroceryCRUD is using a Model that already automated for you pretty much everything (check \GroceryCrud\Core\Model for more). However there are many cases that there are too complex queries that you need to have. In that case you can add a custom model to execute. The syntax is simple:

$model = new customModel($db);
$crud->setModel($model);

A more specific example can be the below:

$crud->setModel(new customModel($db));

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->columns(['customerName','country','state','addressLine1']);

$output = $crud->render();

where $db is the config variable for the database and where customModel is:

<?php 

use GroceryCrud\Core\Model;

class customModel extends Model {

    public function extraWhereStatements($select)
    {
        $select->where("customers.country = 'USA'");
        return $select;
    }
    
}

Note: There will be a separate section that will show you how to create your own unique models for advanced needs. This example is to help you understand the basic usage

The result of the above code is:

Ooooops, something went wrong! If you can see this message, this is probably a misconfiguration in Grocery CRUD Enterprise!