-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWikiProfileController.php
More file actions
33 lines (26 loc) · 975 Bytes
/
WikiProfileController.php
File metadata and controls
33 lines (26 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace App\Http\Controllers;
use App\Helper\ProfileValidator;
use App\Rules\NonEmptyJsonRule;
use App\WikiProfile;
use Illuminate\Http\Request;
class WikiProfileController extends Controller
{
private $profileValidator;
public function __construct(ProfileValidator $profileValidator)
{
$this->profileValidator = $profileValidator;
}
public function create(Request $request): \Illuminate\Http\JsonResponse
{
$wiki = $request->attributes->get('wiki');
$validatedInput = $request->validate([
'profile' => ['required', 'json', new NonEmptyJsonRule]
]);
$rawProfile = json_decode($validatedInput['profile'], true);
$profileValidator = $this->profileValidator->validate($rawProfile);
$profileValidator->validateWithBag('post');
$profile = WikiProfile::create(['wiki_id' => $wiki->id, ...$rawProfile]);
return response()->json(['data' => $profile]);
}
}