|
7 | 7 |
|
8 | 8 | Eloquent flagged attributes behavior. Add commonly used flags to models very quick and easy. |
9 | 9 |
|
| 10 | + |
| 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 | + |
10 | 18 | ## Available flags list |
11 | 19 |
|
12 | 20 | - `is_active` |
@@ -135,23 +143,26 @@ Post::where('id', 4)->unpublish(); |
135 | 143 |
|
136 | 144 | ### Setup a keepable model |
137 | 145 |
|
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. |
139 | 147 |
|
140 | 148 | **Issue:** |
141 | 149 |
|
142 | 150 | 1. User press `Create Post` button. |
143 | 151 | 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. |
145 | 153 |
|
146 | 154 | **Solution:** |
147 | 155 |
|
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). |
149 | 157 | 2. Create empty model on form loading (it will has `is_kept = 0` by default). |
150 | 158 | 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. |
151 | 160 |
|
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:** |
153 | 162 |
|
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). |
155 | 166 |
|
156 | 167 | ```php |
157 | 168 | <?php |
|
0 commit comments