In laravel there are some config files which could be controlled / set with .env file for developing. My question is it possible to set the production values through a db table for example a settings_mail and settings_app table. I need this so that the admin when nessesery could change Some value in a view and doesn't need entering the code
Sure. Create a settings table, like this:
+------------+--------------------+-------------------+
| name | value | category |
+------------+--------------------+---------+---------+
| hostname | smpt.example.com | mail |
+------------+--------------------+-------------------+
| address | San José | general |
+------------+--------------------+-------------------+
You create a setting model based in table structure:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'settings';
protected $name = '';
protected $value = '';
protected $category = '';
}
Load the settings to be accessible at entire application:
// app/Providers/AppServiceProvider.php
public function boot(){
$settings = App\Setting::lists('name', 'value')->all();
config()->set('settings', $settings);
}
Now, get some config:
$address = config('settings.address');