HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/werkenbij.komma.pro/app/Komma/Forms/ApplyController.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 26/09/17
 * Time: 15:24
 */

namespace App\Komma\Forms;

use App\Http\Requests\ApplyRequest;
use App\Komma\Base\Controller;
use App\Komma\Pages\PageController;
use App\Mail\ApplyMail;
use Illuminate\Support\Facades\Mail;

final class ApplyController extends Controller
{
    /**
     * @var FormService
     */
    private $formService;

    /**
     * ContactController constructor.
     * @param FormService $formService
     */
    public function __construct(FormService $formService)
    {
        parent::__construct();

        $this->formService = $formService;
        $this->formService->setOrigin('apply');
    }

    /**
     * Store the request and send it by e-mail
     * Note: Validation is done in the request itself
     *
     * @param ApplyRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function process(ApplyRequest $request)
    {
        // Check for secret code
        if ($request->input('_willie') !== 'wonka') {
            return response()->json([
                'errors' => [
                    '_secretCode' => [
                        __('validation.secretCode')
                    ],
                ],
            ], 422);
        }

        // Store request in the database
        $this->formService->storeRequest($request);
        // Remove token from request (this creates and array)
        $mail = new ApplyMail($request->except('_token', '_willie', '_honey', 'null', 'Documents-resumes_file_catcher', 'Documents-resumes', 'Documents-resumes-1'));
        Mail::send($mail);
        // Return json response with
        return response()->json([
            'redirectUrl' => localized_route('apply.success')
        ]);
    }

    /**
     * Show page where we thank the user
     *
     * @return mixed
     */
    public function success()
    {
        $pageController = new PageController();
        return $pageController->show($this->links->apply->node)->with('send', true);
    }
}