Home > Enterprise >  Dynamic User Defined Tables PHP/Laravel
Dynamic User Defined Tables PHP/Laravel

Time:08-21

I'm working on Laravel based application and need to do the following:

End user should be able create, modify, view and delete their own custom tables and search them using the UI

Relations can also be defined between those tables

For example in PHP I would like to do something like this:

DynamicTable::create('Customers', ['ID', 'First Name', 'Last Name', 'Phone']);

User shouldn't have control over the database, rather they should easily build their own custom data and structure without technical knowledge.

Looking for recommendations for what database and architecture would be scalable and ideal

CodePudding user response:

Do users need to create a custom table or just store custom data? Giving users access to create custom tables/schema directly seems a bit risky?

Would it not be better to store the user defined schema in JSON on mysql JSON column that can then be queried?

As for how you would achieve this with laravel I would imagine you would need to construct your own service class similar to something like:

<?php

namespace App\Service;

class CustomTableService {

   public function create(string $name, array $columns): bool {
       Schema::create($name, function(Blueprint $table) use ($columns) {
           foreach($columns as $name => $type)
           {
               $table->addColumn($type, $name);
           }
       });
   }

}

CodePudding user response:

Looks like you could try a document/nosql database for this. I don’t recommend SQL with such approach, as it defeats the purpose of the structure it offers and would be hard to keep safe.

For example: https://www.mongodb.com/nosql-explained

  • Related