Advanced Usage
Custom Eloquent Model
{note} You're browsing the documentation for an old version of laravel-settings. Consider upgrading your project to v3. Check your version with the following command:
composer show rawilk/laravel-settings
Laravel Settings ships with an Eloquent model for Settings already, but you are free to use your own model. You can either extend
the package's model, or create your own. The only requirement is that it implements the Rawilk\Settings\Contracts\Setting
interface.
Here is what the interface looks like:
namespace Rawilk\Settings\Contracts;
interface Setting
{
public static function getValue(string $key, $default = null);
public static function has($key): bool;
public static function removeSetting($key);
public static function set(string $key, $value = null);
}
Once you have your custom model created, you need to define it in the eloquent
driver in config/settings.php
.
'drivers' => [
'eloquent' => [
'driver' => 'eloquent',
'model' => YourCustomModel::class,
],
],