samedi 4 mai 2019

multiple data storage (database and json) for the same model, how to do it?

Ok, so am having multiple data storage for some models in my project, database storage which ganna save the user data, and a json storage which has a fixed data to compare with the user data.

so, am currently saving the json data in a property in the model after converting it to array, but it is so ANNOYING cause every model now is having a about 500 - 1000 line !

Am wondering, is there a design pattern or something like this which make it easier to relate these data to a model from another file ?

like having model which goal is to fetch the data from the database, and having entity which is related to this model and have this fixed json data on it.

BTW, am using Laravel framework, and my models are Eloquent ORM.

Example:

  class Building {
  protected $table = "buildings";

  //this data is so huge, but i need it to be related to this model so that i can access it from here.
  static $buildings = [
      'Castle' =>
            [
                'name' => 'Castle',
                'objectPath' => '/storage/3D/Land/models/Castle/CastleLevel1.fbx',
                'renderPath' => '/storage/3D/Land/models/Castle/Castle.png',
                'price' => 1000,
                'type' => 'castle',
                'levels' =>[
                    [
                        'upgradeTime' => 100,
                        'upgradeCost' => 100,
                        'requirements' => null
                    ],
                    [
                        'upgradeTime' => 100,
                        'upgradeCost' => 100,
                        'requirements' => null
                    ],
                ]
            ],
      // and so on ..
      ]

    function coordinates()
    {
        return $this->morphOne(Coordinates::class, 'objectable');
    }

    //some functions here which relate this model to another models
}

Aucun commentaire:

Enregistrer un commentaire