PHP code example of alvaro-canepa / oc-trait-utils
1. Go to this page and download the library: Download alvaro-canepa/oc-trait-utils library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alvaro-canepa / oc-trait-utils example snippets
class myModel extend Model {
use PlanetaDelEste\Traits;
...
/**
* @param \October\Rain\Database\Builder|static $query
* @param array $data
*
* @return \October\Rain\Database\Builder|static
* @throws \Exception
*/
public function scopeFrontend($query, $data)
{
$columns = $this->getFullTextIndexFields();
// Search by columns in $data array
foreach ($data as $column => $value) {
if (in_array($column, $columns)) {
$query->where($column, 'LIKE', "%{$value}%");
}
}
// Search in all text columns
if ($q = array_get($data, 'query')) {
foreach ($columns as $column) {
$query->where($column, 'LIKE', "%{$q}%", 'or');
}
}
return $query;
}
}
$myModel = myModel::find(1);
// Methods
/*
* Return array with all model columns.
* Example: ['id', 'created_at', 'updated_at', 'name', 'description']
*/
$myModel->getTableColumns();
/*
* Return array with all text ('VARCHAR', 'TEXT', 'CHAR') columns.
* Example: ['name', 'description']
*/
$myModel->getFullTextIndexFields();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.