FEATURE: add custom fields overview

This commit is contained in:
Michal Kváček
2016-01-27 00:10:13 +01:00
parent 811e0ba5b2
commit 3d110510bc
3 changed files with 81 additions and 13 deletions
+18 -4
View File
@@ -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;
}
}