/ app / Http / Services / InboxConnectionServices / UserInboxConnectionService.php
UserInboxConnectionService.php
 1  <?php
 2  
 3  namespace App\Http\Services\InboxConnectionServices;
 4  
 5  use App\Models\User;
 6  use Illuminate\Http\Client\Response;
 7  use Illuminate\Support\Facades\Http;
 8  
 9  class UserInboxConnectionService
10  {
11      public static function create(User $user): Response
12      {
13          return Http::inbox()->post('/users', [
14              'username' => $user->username,
15              'password' => $user->password,
16              'sgoc_id' => $user->id,
17          ]);
18      }
19  
20      public static function update(User $user, array $updatedFields): ?Response
21      {
22          $data = [];
23  
24          foreach ($updatedFields as $updatedField) {
25              if ($updatedField === 'username' || $updatedField === 'password') {
26                  $data[$updatedField] = $user->$updatedField;
27              }
28          }
29  
30          return count($data) > 0 ? Http::inbox()->put('/users/' . $user->id, $data) : null;
31      }
32  
33      public static function delete(User $user): Response
34      {
35          return Http::inbox()->delete('/users/' . $user->id);
36      }
37  }