update tests
This commit is contained in:
parent
9315dafbfb
commit
f12a83b849
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Activity\Api;
|
namespace App\Activity\Api;
|
||||||
|
|
||||||
use App\Subactivity;
|
use App\Subactivity;
|
||||||
|
use DB;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
|
@ -17,10 +18,12 @@ class SubactivityStoreAction
|
||||||
*/
|
*/
|
||||||
public function handle(array $payload): Subactivity
|
public function handle(array $payload): Subactivity
|
||||||
{
|
{
|
||||||
$subactivity = Subactivity::create(Arr::except($payload, 'activities'));
|
return DB::transaction(function () use ($payload) {
|
||||||
$subactivity->activities()->sync($payload['activities']);
|
$subactivity = Subactivity::create(Arr::except($payload, 'activities'));
|
||||||
|
$subactivity->activities()->sync($payload['activities']);
|
||||||
|
|
||||||
return $subactivity;
|
return $subactivity;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Activity\Api;
|
||||||
use App\Activity;
|
use App\Activity;
|
||||||
use App\Member\Membership;
|
use App\Member\Membership;
|
||||||
use App\Subactivity;
|
use App\Subactivity;
|
||||||
|
use DB;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
@ -21,17 +22,19 @@ class SubactivityUpdateAction
|
||||||
*/
|
*/
|
||||||
public function handle(Subactivity $subactivity, array $payload): Subactivity
|
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')) {
|
if (null !== data_get($payload, 'activities')) {
|
||||||
$subactivity->activities()->sync($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
|
public function rules(): array
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue