Skip to content

Commit 419b8d0

Browse files
Add example to readme intro
1 parent 170a550 commit 419b8d0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,41 @@
1010
[![Follow @sebastiaanluca on Twitter][twitter-profile-badge]][link-twitter]
1111
[![Share this package on Twitter][twitter-share-badge]][link-twitter-share]
1212

13-
__Sets the date of fields to the current date and time if an inputted counterpart boolean field is true-ish.__ Ideal for those terms and conditions checkboxes on user registration pages! Now you know _when_ they were accepted and not just _if_ (GDPR anyone?).
13+
__Sets the date of an attribute to the current date and time if an inputted counterpart boolean attribute is true-ish.__
14+
15+
### Example
16+
17+
Say you've got a registration page for users where they need to accept your terms and perhaps can opt-in to certain features using checkboxes. With the new(-ish) GDPR privacy laws, you're somewhat required to not just keep track of the fact *if* they accepted those (or not), but also *when* they did.
18+
19+
**This package automatically converts those boolean fields to dates so you always know when something was accepted.**
20+
21+
User registration controller:
22+
23+
```php
24+
$input = $request->input();
25+
26+
$user = User::create([
27+
'has_accepted_terms_and_conditions' => $input['terms'],
28+
'allows_data_processing' => $input['data_processing'],
29+
'has_agreed_to_something' => $input['something'],
30+
]);
31+
```
32+
33+
Anywhere else in your code:
34+
35+
```php
36+
$user->has_accepted_terms_and_conditions;
37+
38+
/*
39+
* true or false (boolean)
40+
*/
41+
42+
$user->accepted_terms_and_conditions_at;
43+
44+
/*
45+
* 2018-05-10 16:24:22 (string or Carbon instance)
46+
*/
47+
```
1448

1549
## Table of contents
1650

0 commit comments

Comments
 (0)