45 lines
899 B
PHP
45 lines
899 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class CustomField
|
|
*/
|
|
class CustomField extends Model
|
|
{
|
|
public $timestamps = false;
|
|
protected $fillable = [
|
|
'name',
|
|
'type_id',
|
|
'resource_id',
|
|
'description',
|
|
'possible_values',
|
|
'default_value',
|
|
'regexp',
|
|
'min_length',
|
|
'max_length',
|
|
'required'
|
|
];
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* Getter for all custom fields indexed by resource ID.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getIndexedByResource()
|
|
{
|
|
// find all records in table
|
|
$fields = CustomField::all();
|
|
|
|
// add them to array indexed by resource ID
|
|
$customFields = [];
|
|
foreach ($fields as $field) {
|
|
$customFields[$field->resource_id][] = $field;
|
|
}
|
|
|
|
return $customFields;
|
|
}
|
|
} |