Home > Mobile >  I want to modify array-column output when fetched
I want to modify array-column output when fetched

Time:06-08

This is my data table image this is my data table image

my blade file

@table([
    'id' => 'Persons.index',
    'xhr' => route('api.manage-dup-api'),
    'ns' => 'PersonsIndex',
    'columns' => $columns ?? [],
    'filters' => $filterTable ?? [],
    'params' => [
        'filters_live' => false,
        'selectable' => true,
        'toolbar_style' => 'fixed'
    ]
])

this is a query which passes data to a data table [API]

 $q->with('user')
            ->with('user.roles')
            ->select(
                'persons.*',
                'birth->date as birthdate'
            )->`enter code here`whereIn('id', $id)->orWhereIn('old_id_CONINET', $coninet_ids);
        return $this->outputList($q, $request);

as shown in the picture I want to remove ["] from the CONINET_ID table

CodePudding user response:

you are storing an array of strings in the DB.

you can convert the array values to int:

array_map('intval', $array);

you can also create an accessor on your eloquent model

public function getOldIdConinetAttribute($value)
{
    return array_map('intval', $value);
}

CodePudding user response:

It would better if you give some detailed info. As of now details mentioned above can not explain your code. As of my understanding, I suggest you to check Yajra datatable plugin which will help you solving your issue.

or you can cast coninet_id to array by adding below code in your model.

protected $casts = [
'coninet_id' => 'array'
];
  • Related