dimanche 22 décembre 2019

Store a object directly on ORM Laravel?

I search for all the web and don't find a solution other than a custom function that we must make. I develops in Node.js and Laravel backend applications.

And in Node.js we send a object exacly equal to the database collumns and we just use Sequelize insert function like this:

  async store(model) {
    try {
      await this.model.city.create(model);
    } catch (error) {
      throw error;
    }
  }

We simply use the same object that sending from the app we store like this store(object); and works fine.

In Laravel I always must reference the columns even so the objects have the same atributes from the collumns on database, like this:

    $categoryObj = new Category;
    $categoryObj->name = $category['name'];
    $categoryObj->save();
    return $categoryObj;

I want to just make something like this:

    $categoryObj = new Category;
    $categoryObj = $category;
    $categoryObj->save();
    return $categoryObj;

It is possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire