Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yazan-alnugnugh committed Feb 28, 2022
1 parent e41fbd0 commit 1684433
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"Yazan\\Setting\\Tests\\SettingTest::translated_in_scope_returns_only_translated_records_for_this_locale":3,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_set_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clear_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clean_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clearGroup":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_cleanGroup_values":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_group":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_groups":4,"Warning":6,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_set_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clear_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clean_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_group":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_groups":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clearGroup":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_cleanGroup_values":4},"times":{"Yazan\\Setting\\Tests\\SettingTest::translated_in_scope_returns_only_translated_records_for_this_locale":0.195,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_key_value":0.01,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_set_key_value":0.213,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clear_key_value":0.009,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clean_key_value":0.008,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clearGroup":0.009,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_cleanGroup_values":0.008,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_group":0.009,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_groups":0.01,"Warning":0,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_key_value":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_set_key_value":0.011,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clear_key_value":0.008,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clean_key_value":0.01,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_group":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_groups":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clearGroup":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_cleanGroup_values":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_settings_attribute":0.008,"Yazan\\Setting\\Tests\\SettingsAttributeTestTest::it_can_get_settings_attribute":0.009}}
{"version":1,"defects":{"Yazan\\Setting\\Tests\\SettingTest::translated_in_scope_returns_only_translated_records_for_this_locale":3,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_set_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clear_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clean_key_value":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clearGroup":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_cleanGroup_values":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_group":4,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_groups":4,"Warning":6,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_set_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clear_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clean_key_value":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_group":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_groups":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clearGroup":4,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_cleanGroup_values":4,"Yazan\\Setting\\Tests\\SettingsAttributeTest::it_can_get_settings_attribute":4},"times":{"Yazan\\Setting\\Tests\\SettingTest::translated_in_scope_returns_only_translated_records_for_this_locale":0.195,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_key_value":0.007,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_set_key_value":0.185,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clear_key_value":0.007,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clean_key_value":0.007,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_clearGroup":0.007,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_cleanGroup_values":0.007,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_group":0.008,"Yazan\\Setting\\Tests\\GeneralSettingTest::it_can_get_groups":0.007,"Warning":0,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_key_value":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_set_key_value":0.009,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clear_key_value":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clean_key_value":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_group":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_groups":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_clearGroup":0.008,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_cleanGroup_values":0.007,"Yazan\\Setting\\Tests\\ModelSettingTest::it_can_get_settings_attribute":0.008,"Yazan\\Setting\\Tests\\SettingsAttributeTestTest::it_can_get_settings_attribute":0.008,"Yazan\\Setting\\Tests\\SettingsAttributeTest::it_can_get_settings_attribute":0.009}}
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
![npm](https://img.shields.io/npm/dm/@yazan.alnughnugh/laravel-settings)
![GitHub](https://img.shields.io/github/license/yazan-alnugnugh/laravel-datatable?color=blue)
<h2 align="center">Supporting Laravel Settings Package</h2>

- [Become sponsor on Patreon](https://www.patreon.com/yazan_alnughnugh).
Expand All @@ -12,7 +10,7 @@
<img src="art/Laravel-setting.png" alt="laravel-vue-datatable intro image">
</p>

**do would like to add settings to your website or to your model this package created for that.**
**do you would like to add settings to your website or to your model this package created for that.**

The Laravel Settings created to allow you to add general settings to your website
simple and easy way also you can add settings for the specific model item,
Expand All @@ -25,14 +23,6 @@ The Laravel Settings created to allow you to add general settings to your websit



## Demo

[DataTable Demo](https://packages.tourismcaravan.com/data-table)





## Quick Example


Expand Down Expand Up @@ -70,3 +60,22 @@ Here we retrieve Setting from model
$user->getSetting('age');

```

also, we can retrieve Setting as a group
```php

$user->getSettingGroup('default');

```

### Tests

to start the Test Laravel settings package we can use the composer command.

```push
composer test
```


19 changes: 0 additions & 19 deletions src/Databases/factories/SettingFactories.php

This file was deleted.

15 changes: 8 additions & 7 deletions src/Interfaces/SettingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

interface SettingInterface
{
public static function get($key, string $group = 'default');
public static function set($key, $value, string $group = 'default');
public static function clear($key, string $group = 'default');
public static function clean($key, string $group = 'default');
public static function clearGroup(string $group = 'default');
public static function cleanGroup(string $group = 'default');
public static function group(string $group = 'default');
public static function get($key, $group);
public static function set($key, $value, $group);
public static function clear($key, $group);
public static function clean($key, $group);
public static function clearGroup($group);
public static function cleanGroup($group);
public static function group($group);
public static function groups();
}
16 changes: 8 additions & 8 deletions src/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class Setting extends Model implements SettingInterface
{
use Scope;

public static function get($key, string $group = 'default')
public static function get($key, $group = 'default')
{
$setting = (new self)->relationNull()->where('key', $key)->
where('group', $group)->pluck('value');
return optional($setting)[0];

}

public static function set($key, $value, string $group = 'default')
public static function set($key, $value, $group = 'default')
{

$setting = (new self)->updateOrCreate(
Expand All @@ -29,7 +29,7 @@ public static function set($key, $value, string $group = 'default')
return $setting;
}

public static function clear($key, string $group = 'default')
public static function clear($key, $group = 'default')
{
$setting = (new self)->relationNull()
->where('key', $key,)
Expand All @@ -40,28 +40,28 @@ public static function clear($key, string $group = 'default')

}

public static function clean($key,string $group = 'default')
public static function clean($key, $group = 'default')
{
return $setting = (new self)->relationNull()
->where('key', $key,)
->where('group', $group,)
->update(['value' => '']);
->update(['value' => null]);

}

public static function clearGroup(string $group = 'default')
public static function clearGroup( $group = 'default')
{
return (new self)->relationNull()->where('group', $group,)->delete();

}

public static function cleanGroup(string $group = 'default')
public static function cleanGroup( $group = 'default')
{
return (new self)->relationNull()->where('group', $group,)->update(['value' => '']);

}

public static function group(string $group = 'default')
public static function group( $group = 'default')
{
$group = (new self)->relationNull()->where('group', $group,)->get(['key', 'value'])->toArray();

Expand Down
12 changes: 10 additions & 2 deletions src/SettingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yazan\Setting;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;
use Yazan\DataTable\Commands\DataTableCommand;

class SettingServiceProvider extends ServiceProvider
Expand All @@ -14,7 +15,10 @@ class SettingServiceProvider extends ServiceProvider
*/
public function register()
{
//
$this->app->booting(function() {
$loader = AliasLoader::getInstance();
$loader->alias('Setting', Setting::class);
});

}

Expand All @@ -27,7 +31,11 @@ public function boot()
{
//

$this->loadMigrationsFrom(__DIR__ . '/Databases/migrations');
// $this->loadMigrationsFrom(__DIR__ . '/Databases/migrations');

$this->publishes([
__DIR__.'/Databases/migrations' => database_path('migrations')
], 'settings');

}
}
2 changes: 1 addition & 1 deletion src/Traits/HasSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function cleanSetting($key, $group = 'default'){
return $this->setting()
->where('key', $key)
->where('group', $group)
->update(['value' => '']);
->update(['value' => null]);
}
public function clearSettingGroup($group = 'default'){
return $this->setting()
Expand Down
2 changes: 1 addition & 1 deletion tests/SettingsAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yazan\Setting\Models\User;
use Yazan\Setting\Setting;

class SettingsAttributeTestTest extends TestCase
class SettingsAttributeTest extends TestCase
{
public $settings = [
'default' => [
Expand Down
23 changes: 9 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ protected function setUp(): void

$this->createTables();

$this->withFactories(realpath('/factories'));
}

// protected function getEnvironmentSetUp($app)
// {
// $app['config']->set('translatable.locales', ['el', 'en', 'fr', 'de', 'id', 'en-GB', 'en-US', 'de-DE', 'de-CH']);
// }

protected function getPackageProviders($app)
{
Expand All @@ -35,15 +30,15 @@ protected function getPackageProviders($app)

protected function createTables(): void
{
// Schema::create('settings', function (Blueprint $table) {
// $table->bigIncrements('id');
// $table->string('key');
// $table->string('value')->nullable();
// $table->string('group');
// $table->string('model_type')->nullable();
// $table->bigInteger('model_id')->nullable();
// $table->timestamps();
// });
Schema::create('settings', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('key');
$table->string('value')->nullable();
$table->string('group');
$table->string('model_type')->nullable();
$table->bigInteger('model_id')->nullable();
$table->timestamps();
});

Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
Expand Down
14 changes: 0 additions & 14 deletions tests/factories/SettingFactory.php

This file was deleted.

0 comments on commit 1684433

Please sign in to comment.