app/Http/Controllers/AdminController.php
/**
     * @param Request $request
     * @param AdminService $adminService
     * @return JsonResponse
     * @throws ValidationException
     */
@param Request $request
@param AdminService $adminService
@return JsonResponse
@throws ValidationException
@param Request $request @param AdminService $adminService @return JsonResponse @throws ValidationException
public function createPost(Request $request, AdminService $adminService): JsonResponse
    {
        $body = trim($request->post('body'));
        $bodyStripped = str_replace('&nbsp;', '', strip_tags($body));
        $messages = [
            'title.required' => 'Pealkiri on kohustuslik!',
            'body.required' => 'Sisu on kohustuslik!'
        ];
        $validator = Validator::make([
            'title' => $request->post('title'),
            'body' => $bodyStripped
        ], [
            'body' => 'required',
            'title' => 'required',
        ], $messages);
        $validator->validate();
        try {
            $post = $adminService->createPost(
                $request->post('title'),
                $body
            );
            return response()->json([
                'id' => $post->id
            ]);
        } catch (\Exception $e) {
            return response()->json(null, 500);
        }
    }
public function createPost ( Request $ request , AdminService $ adminService ) : JsonResponse { $ body = trim ( $ request -> post ( 'body' ) ) ; $ bodyStripped = str_replace ( '&nbsp;' , '' , strip_tags ( $ body ) ) ; $ messages = [ 'title.required' => 'Pealkiri on kohustuslik!' , 'body.required' => 'Sisu on kohustuslik!' ] ; $ validator = Validator :: make ( [ 'title' => $ request -> post ( 'title' ) , 'body' => $ bodyStripped ] , [ 'body' => 'required' , 'title' => 'required' , ] , $ messages ) ; $ validator -> validate ( ) ; try { $ post = $ adminService -> createPost ( $ request -> post ( 'title' ) , $ body ) ; return response ( ) -> json ( [ 'id' => $ post -> id ] ) ; } catch ( \ Exception $ e ) { return response ( ) -> json ( null , 500 ) ; } }
@param Request $request
 @param AdminService $adminService
 @return JsonResponse
 @throws ValidationException
@param Request $request @param AdminService $adminService @return JsonResponse @throws ValidationException