Dynamic custom field management trait allowing entities to define and persist custom schema-less fields stored as JSON, used across customer, contact, and contract modules.
<?php
namespace App\Admin\Traits;
use Dcat\Admin\Grid;
use App\Models\CrmCustomfield;
use Dcat\Admin\Form;
trait Customfields
{
protected function custommodel($modelname)
{
$fields = CrmCustomfield::where([['model', '=', $modelname], ['show', '=', '1']])->orderBy('sort', 'desc')->get();
// return dd($fields);
return $fields;
}
protected function gridfield(Grid $grid, $modelname)
{
$fields = CrmCustomfield::where([['model', '=', $modelname], ['show', '=', '1'], ['iflist', '=', '1']])->orderBy('sort', 'desc')->get();
foreach ($fields as $field) {
$grid->column($field['field'], $field['name'])->display(function () use ($field) {
$form_fields = json_decode($this->fields);
$field_options
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key