Update::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Families;
4
5
use App\Http\Requests\ValidateFamilyRequest;
6
use App\Models\Family;
7
use App\Models\Person;
8
use Illuminate\Routing\Controller;
9
10
class Update extends Controller
11
{
12
    public function __invoke(ValidateFamilyRequest $request, $family)
13
    {
14
        $family = Family::find($family);
15
16
        if ($family) {
17
            $family->update($request->validated());
18
            $family->children()->update(['child_in_family_id' => null]);
19
            $family->children()->saveMany(Person::whereIn('id', $request->get('child_id', []))->get());
20
        }
21
        //return with 404
22
23
        return ['message' => __('The family was successfully updated')];
24
    }
25
}
26