- admin can edit, approve or reject broker registration - admin can edit, delete or impersonate as broker
31 lines
746 B
PHP
31 lines
746 B
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
final readonly class UpdateBrokerAction
|
|
{
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function execute(array $data, User $profile): void
|
|
{
|
|
/**
|
|
* Separate the user fields from the broker fields
|
|
*/
|
|
$userFields = ['name', 'email'];
|
|
$data = collect($data);
|
|
$profileData = $data->only($userFields)->toArray();
|
|
$userData = $data->except($userFields)->toArray();
|
|
|
|
DB::transaction(function () use ($profileData, $profile, $userData) {
|
|
$profile->update($profileData);
|
|
$user = $profile->type;
|
|
$user->update($userData);
|
|
});
|
|
}
|
|
}
|