Skip to content

Commit 2de8d1e

Browse files
committed
Extend documentation
1 parent 4c74784 commit 2de8d1e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
Eloquent flagged attributes behavior. Add commonly used flags to models very quick and easy.
99

10+
![cog-laravel-eloquent-flag](https://cloud.githubusercontent.com/assets/1849174/21166452/b1bbf3e8-c1b6-11e6-8f06-468828402ebe.png)
11+
12+
## How it works
13+
14+
Eloquent Flag is an easy way to add flagged attributes to eloquent models. All flags has their own trait which adds global scopes to desired entity.
15+
16+
The main logic of the flags: If flag is `false` - entity should be hidden from the query results. Omitted entities could be retrieved by using a global scope methods.
17+
1018
## Available flags list
1119

1220
- `is_active`
@@ -135,23 +143,26 @@ Post::where('id', 4)->unpublish();
135143
136144
### Setup a keepable model
137145
138-
Keep functionality required when you are trying to attach related models before parent one isn't saved.
146+
Keep functionality required when you are trying to attach related models before parent one isn't persisted in application.
139147
140148
**Issue:**
141149
142150
1. User press `Create Post` button.
143151
2. Create post form has image uploader.
144-
3. On image uploading user can't attach image to post before it wouldn't been stored in database.
152+
3. On image uploading user can't attach image to post before post entity wouldn't been stored in database.
145153
146154
**Solution:**
147155
148-
1. Add `HasKeptFlag` trait to model (and add boolean `is_kept` column to database).
156+
1. Add `HasKeptFlag` trait to model (and add boolean `is_kept` column to model's database table).
149157
2. Create empty model on form loading (it will has `is_kept = 0` by default).
150158
3. Feel free to add any relations to the model.
159+
4. Model will be marked as required to be kept as soon as model will be saved\updated for the first time after creation.
151160
152-
*Model will be marked as required to be kept as soon as client will save\update model for the first time.*
161+
**Known limitations:**
153162
154-
*Remove the unkept models on a predetermined schedule (once a week for example).*
163+
- Using this methodology you wouldn't have create form, only edit will be available.
164+
- Not all the models allows to have empty attributes on save. Such attributes could be set as nullable to allow create blank model.
165+
- To prevent spam of unkept models in database they could be deleted on a predetermined schedule (once a week for example).
155166
156167
```php
157168
<?php

0 commit comments

Comments
 (0)