update tests

This commit is contained in:
philipp lang 2023-03-07 00:25:11 +01:00
parent 9315dafbfb
commit f12a83b849
2 changed files with 15 additions and 9 deletions

View File

@ -3,6 +3,7 @@
namespace App\Activity\Api;
use App\Subactivity;
use DB;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Lorisleiva\Actions\ActionRequest;
@ -17,10 +18,12 @@ class SubactivityStoreAction
*/
public function handle(array $payload): Subactivity
{
$subactivity = Subactivity::create(Arr::except($payload, 'activities'));
$subactivity->activities()->sync($payload['activities']);
return DB::transaction(function () use ($payload) {
$subactivity = Subactivity::create(Arr::except($payload, 'activities'));
$subactivity->activities()->sync($payload['activities']);
return $subactivity;
return $subactivity;
});
}
/**

View File

@ -5,6 +5,7 @@ namespace App\Activity\Api;
use App\Activity;
use App\Member\Membership;
use App\Subactivity;
use DB;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
@ -21,17 +22,19 @@ class SubactivityUpdateAction
*/
public function handle(Subactivity $subactivity, array $payload): Subactivity
{
$subactivity->update(Arr::except($payload, 'activities'));
return DB::transaction(function () use ($subactivity, $payload) {
$subactivity->update(Arr::except($payload, 'activities'));
if (null !== data_get($payload, 'activities')) {
$subactivity->activities()->sync($payload['activities']);
}
if (null !== data_get($payload, 'activities')) {
$subactivity->activities()->sync($payload['activities']);
}
return $subactivity;
return $subactivity;
});
}
/**
* @return array<string, string>
* @return array<string, string|array<int, mixed>>
*/
public function rules(): array
{