FEATURE: add custom fields overview
This commit is contained in:
@@ -9,9 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class CustomField extends Model
|
||||
{
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'type_id',
|
||||
@@ -24,8 +22,24 @@ class CustomField extends Model
|
||||
'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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user