Skip to content

Commit 710f770

Browse files
committed
initial commit
0 parents  commit 710f770

File tree

14 files changed

+5576
-0
lines changed

14 files changed

+5576
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

CODE_OF_CONDUCT.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Code of Conduct
2+
3+
### Our Pledge
4+
5+
We, as contributors and maintainers, pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
### Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
- Using welcoming and inclusive language
12+
- Being respectful of differing viewpoints and experiences
13+
- Gracefully accepting constructive criticism
14+
- Focusing on what is best for the community
15+
- Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
- The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
- Trolling, insulting or derogatory comments, and personal or political attacks
21+
- Public or private harassment
22+
- Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
- Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
### Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
### Scope
32+
33+
This Code of Conduct applies within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
### Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
### Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
44+
45+
For answers to common questions about this code of conduct, see [FAQ](https://www.contributor-covenant.org/faq).

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributing
2+
3+
We welcome and encourage community contributions to enhance the "Laravel Settings" package. Whether you want to report a bug, suggest a new feature, or actively participate in development, your input is invaluable.
4+
5+
Here's how you can get involved:
6+
7+
1. **Reporting Issues:**
8+
9+
- If you encounter a bug or have a suggestion for an improvement, please open an issue on our [GitHub repository](https://github.com/ruangdeveloper/laravel-settings/issues).
10+
11+
2. **Feature Requests:**
12+
13+
- If you have an idea for a new feature or enhancement, feel free to create an issue on our GitHub repository with the "Feature Request" label. We'll review and discuss it with the community.
14+
15+
3. **Pull Requests:**
16+
17+
- If you're a developer and would like to contribute directly, you can submit a pull request. Please ensure the following:
18+
- Fork the repository and create a feature branch for your changes.
19+
- Write clear and comprehensive documentation for new features.
20+
- Make sure your code adheres to our coding standards and passes any existing tests.
21+
- Open a pull request with a detailed description of the changes you've made.
22+
23+
4. **Documentation:**
24+
25+
- We greatly appreciate improvements to our documentation. If you find gaps or have suggestions for clearer explanations, please submit documentation updates.
26+
27+
5. **Spreading the Word:**
28+
- If you enjoy using "Laravel Settings," consider sharing it with others. The more users and contributors we have, the better the package becomes.
29+
30+
By participating in this open-source project, you become an integral part of the "Laravel Settings" community, and together we can create a powerful and versatile package.
31+
32+
**Code of Conduct:**
33+
34+
To ensure a welcoming and respectful environment for all contributors, please review and abide by our [Code of Conduct](https://github.com/ruangdeveloper/laravel-settings/CODE_OF_CONDUCT.md). We have a zero-tolerance policy for harassment or discrimination, and we're committed to fostering a collaborative and inclusive community.
35+
36+
Thank you for considering contributing to "Laravel Settings." Your involvement helps us improve and expand the package, benefiting developers worldwide.

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Ruang Developer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# Laravel Settings
2+
3+
Introducing "Laravel Settings" – a powerful and flexible Laravel package designed to simplify the management of application settings, both at the global and model-specific levels. With this package, developers can effortlessly store, retrieve, and customize settings within the database, enhancing the configuration and flexibility of Laravel-based projects.
4+
5+
Whether you need to manage site-wide configurations, user preferences, or any other form of customizable settings, "Laravel Settings" provides an elegant solution to streamline the process. It offers a clean and intuitive API, ensuring that you can get started quickly without any steep learning curve.
6+
7+
## Key Features:
8+
9+
- Global and Model-Specific Settings: "Laravel Settings" allows you to define both global settings, which apply to your entire application, and model-specific settings, which are associated with specific Eloquent models.
10+
11+
- Easy Configuration: You can define settings in a configuration file, making it a breeze to set up and manage your application's settings.
12+
13+
- Customizable: The package offers the flexibility to create custom setting types, ensuring that you can handle various data types, validation rules, and display options.
14+
15+
- Eloquent Integration: "Laravel Settings" seamlessly integrates with Laravel's Eloquent ORM, enabling you to link settings to specific database records.
16+
17+
## Requirements
18+
19+
- Laravel ^10.0
20+
21+
## Installation:
22+
23+
To get started with "Laravel Settings," follow these simple installation steps:
24+
25+
Install the package via Composer:
26+
27+
```bash
28+
composer require ruangdeveloper/laravel-settings
29+
```
30+
31+
**Publish the configuration file:**
32+
33+
```bash
34+
php artisan vendor:publish --provider="RuangDeveloper\LaravelSettings\LaravelSettingsServiceProvider" --tag="config"
35+
```
36+
37+
Configure the settings in `config/laravel-settings.php` according to your application's requirements.
38+
39+
**Publish the migration file**
40+
41+
```bash
42+
php artisan vendor:publish --provider="RuangDeveloper\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
43+
```
44+
45+
## Usage
46+
47+
Let's take a quick look at how you can use "Laravel Settings" to manage a global setting for your application.
48+
49+
**Set a global setting**
50+
51+
```php
52+
use RuangDeveloper\LaravelSettings\Facades\Settings;
53+
54+
// setting the global site title
55+
Settings::set('site_title', 'Your Awesome Website');
56+
57+
```
58+
59+
**Get a global setting**
60+
61+
```php
62+
use RuangDeveloper\LaravelSettings\Facades\Settings;
63+
64+
// retrieve the global site title
65+
$siteTItle = Settings::get('site_title');
66+
67+
// you may want to add a default fallback value if the setting
68+
// with provided key doesn't exists in the database
69+
$siteTitle = Settings::get('site_title', 'Your Default Awesome Website');
70+
```
71+
72+
### Forget a global setting
73+
74+
Now, if you want to delete the setting
75+
76+
```php
77+
use RuangDeveloper\LaravelSettings\Facades\Settings;
78+
79+
Settings::forget('site_title');
80+
```
81+
82+
## Model Specific Setting
83+
84+
This package allow you to link the setting to a specific model. For example, you may want to store user's preferences.
85+
86+
**Model Configuration**
87+
The first step before linking the setting to a specific model, you need to configure your model to use the `HasSettings` traits.
88+
89+
```php
90+
use Illuminate\Database\Eloquent\Model;
91+
use RuangDeveloper\LaravelSettings\Traits\HasSettings;
92+
93+
class User extends Model
94+
{
95+
use HasSettings; // use the HasSettings trait
96+
97+
protected $guarded = [];
98+
}
99+
100+
```
101+
102+
Now, you can use the setting for an user.
103+
104+
**Set a setting**
105+
106+
```php
107+
$user = App\Models\User::find(1);
108+
$user->setSetting('subscribe_newsletter', true);
109+
```
110+
111+
**Get a setting**
112+
113+
```php
114+
$user = App\Models\User::find(1);
115+
$isSubscribed = $user->getSetting('subscribe_newsletter');
116+
117+
// you may want to add a default fallback value if the setting
118+
// with provided key doesn't exists in the database
119+
$isSubscribed = $user->getSetting('subscribe_newsletter', false);
120+
//
121+
```
122+
123+
**Forget a setting**
124+
125+
```php
126+
$user = App\Models\User::find(1);
127+
$user->forgetSetting('subscribe_newsletter');
128+
```
129+
130+
## Default Settings
131+
132+
You may want add default settings value for global or model specific settings. You can add these settings value in the configuration file located at `configs/laravel-settings.php`.
133+
134+
> Note: if you cannot find the config file, you need to publish the configuration first.
135+
136+
**Default global settings**
137+
138+
```php
139+
return [
140+
// others config
141+
142+
'defaults' => [
143+
'site_title' => 'Your Awesome Site',
144+
],
145+
];
146+
```
147+
148+
Now, you will always get the default site title setting if there is no setting stored in the database.
149+
150+
```php
151+
use RuangDeveloper\LaravelSettings\Facades\Settings;
152+
153+
154+
$siteTItle = Settings::get('site_title');
155+
156+
echo $siteTitle; // Your Awesome Site
157+
```
158+
159+
**Default model specific settings**
160+
161+
```php
162+
return [
163+
// others config
164+
165+
'model_defaults' => [
166+
'App\Models\User' => [
167+
'subscribe_newsletter' => false
168+
],
169+
],
170+
];
171+
```
172+
173+
Now, you will always get the default subscribe newsletter setting when you try to retrieve it from an user that didn't have setting for subscribe newsletter.
174+
175+
```php
176+
$user = App\Models\User::find(1);
177+
$isSubscribed = $user->getSetting('subscribe_newsletter');
178+
179+
echo $isSubscribed // false
180+
```
181+
182+
## Customization
183+
184+
### Using Your Own Model
185+
186+
While this package covers almost everything that you need to manage the settings, you may want to use your own model. To do this, you can extends the Setting model from this package.
187+
188+
```php
189+
use RuangDeveloper\LaravelSettings\Models\Setting;
190+
191+
class CustomSetting extends Setting
192+
{
193+
//
194+
}
195+
```
196+
197+
After that, you need to tell this package to use the model you just created. Please update in the `configs/laravel-settings.php`.
198+
199+
```php
200+
return [
201+
// others config
202+
203+
'model' => App\Models\CustomSetting::class,
204+
];
205+
```
206+
207+
Certainly, adding a "Contributing" section to your package's documentation is a great way to invite other developers to collaborate and make your package even better. Here's a sample "Contributing" section that you can include:
208+
209+
# Contributing
210+
211+
https://github.com/ruangdeveloper/laravel-settings/CONTRIBUTING.md
212+
213+
# License
214+
215+
https://github.com/ruangdeveloper/laravel-settings/LICENSE.md

composer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "ruangdeveloper/laravel-settings",
3+
"description": "Manage model or application settings in database",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"RuangDeveloper\\LaravelSettings\\": "src/"
9+
}
10+
},
11+
"extra": {
12+
"laravel": {
13+
"providers": [
14+
"RuangDeveloper\\LaravelSettings\\LaravelSettingsServiceProvider"
15+
]
16+
}
17+
},
18+
"authors": [
19+
{
20+
"name": "Ruang Developer",
21+
"email": "[email protected]"
22+
}
23+
],
24+
"minimum-stability": "dev",
25+
"prefer-stable": true,
26+
"require": {
27+
"laravel/framework": "^10.0.0"
28+
}
29+
}

0 commit comments

Comments
 (0)