You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-14Lines changed: 78 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,6 @@
1
1
# Simple Actionable for Laravel
2
2
3
-
[](https://packagist.org/packages/cleaniquecoders/laravel-action)
$action->setProperty('constrainedBy', ['email' => 'johndoe@example.com']); // Use email as a unique constraint
71
+
```
72
+
73
+
This flexible property setting reduces boilerplate and simplifies configuration of actions.
74
+
75
+
#### 2. Field Transformation with Hashing and Encryption
76
+
77
+
The `ResourceAction` class supports field-level transformations. For example, you can hash a `password` field and encrypt an `ssn` field:
54
78
55
79
```php
56
-
use App\Actions\User\CreateOrUpdateUser;
80
+
$inputs = [
81
+
'name' => 'Jane Doe',
82
+
'email' => 'janedoe@example.com',
83
+
'password' => 'securepassword',
84
+
'ssn' => '123-45-6789',
85
+
];
86
+
87
+
$action = new CreateOrUpdateUser($inputs);
88
+
$action->setProperty('hashFields', ['password']);
89
+
$action->setProperty('encryptFields', ['ssn']);
90
+
$record = $action->execute();
91
+
```
92
+
93
+
After execution:
94
+
- The `password` field will be hashed for security.
95
+
- The `ssn` field will be encrypted, ensuring secure storage.
57
96
58
-
$user = (new CreateOrUpdateUser(['name' => 'Nasrul Hazim', 'email' => 'nasrul@work.com']));
97
+
#### 3. Constraint-Based `updateOrCreate`
59
98
60
-
// do more with \App\Models\User object
61
-
// $user->assignRole(...)
99
+
You can specify constraints to perform `updateOrCreate` actions based on unique fields or identifiers. Here’s an example of updating an existing user by `id`:
100
+
101
+
```php
102
+
// Assume there's an existing user with this email
103
+
$existingUser = User::create([
104
+
'name' => 'Old Name',
105
+
'email' => 'uniqueemail@example.com',
106
+
'password' => Hash::make('oldpassword'),
107
+
]);
108
+
109
+
// Define the inputs to update the existing user
110
+
$inputs = [
111
+
'name' => 'John Doe Updated',
112
+
'email' => 'uniqueemail@example.com', // Same email
113
+
'password' => 'newpassword',
114
+
];
115
+
116
+
$action = new CreateOrUpdateUser($inputs);
117
+
$action->setProperty('constrainedBy', ['id' => $existingUser->id]); // Update by user ID
118
+
119
+
$record = $action->execute();
120
+
121
+
// The existing user record with the specified ID will be updated.
62
122
```
63
123
124
+
This allows precise control over `updateOrCreate` behavior based on custom constraints.
125
+
64
126
## Testing
65
127
128
+
Run the tests with:
129
+
66
130
```bash
67
131
composer test
68
132
```
69
133
70
134
## Changelog
71
135
72
-
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
136
+
Please see [CHANGELOG](CHANGELOG.md) for more information on recent changes.
0 commit comments