vendredi 14 mai 2021

Is it possible to add an object structure under an array to the Eloquent model scheme?

I got a JSON object like this:

{
   "campaignDesignerAccountId":0,
   "remoteAccountId":0,
   "month":5,
   "usage":[
      {
         "service":"affectivity",
         "type":"renderVideo",
         "taskCount":"59",
         "totalDuration":"2597.845625400543"
      },
      {
         "service":"creatives",
         "type":"HTMLToPDF",
         "taskCount":"248",
         "totalDuration":"5412.990473032003"
      },
      {
         "service":"creatives",
         "type":"pdf",
         "taskCount":"229",
         "totalDuration":"27953.42511272434"
      },
      {
         "service":"displayads",
         "type":"html5",
         "taskCount":"8",
         "totalDuration":"199.255334138869"
      }
   ]
}

I want to add the object under the usage array as an eloquent model schema.

For example:

    protected $fillable = [
        'campaignDesignerAccountId',
        'remoteAccountId',
        '[usage].service',
        '[usage].type',
        '[usage].taskCount',
        '[usage].totalDuration',
        'month',

    ];

Is it possible?

Currently, my eloquent model looks like this:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PublishEngineMonthlyLogs extends Model
{

    protected $fillable = [
        'campaignDesignerAccountId',
        'remoteAccountId',
        'usage',
        'month'

    ];

    protected $casts = [
        'usage' => 'array'
    ];

    // Sorting parameters
    protected $allowedSorts = [
        'month'
    ];

    // Permission of filtering fields with texts
    protected $allowedFilters = [
        'month',
        'campaignDesignerAccountId'
    ];
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire