I'm working on a customizable webshop in laravel. I'm thinking about how to achieve that the admin can edit the settings of the webshop and store the changes like: phone number, email, logo, what elements can be in the navigation etc. If I stored it in a "settings" table in the database there would be one row and I would somehow need to restrict the creation of another one.
Is it an accepted method or there is a better approach?
You can create a kind of key -> value table and make key field unique.
This will make sure that the data is not duplicated anywhere.
Add with the seeder test data and allow users to change the value, not the key.
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('value');
$table->unique('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('settings');
}