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/ZelfVerkopen/zelfverkopen.nl/app/KommaApp/Forms/PropertyPlanVisitController.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 26/09/17
 * Time: 15:24
 */

namespace App\KommaApp\Forms;

use App\Http\Controllers\Controller;
use App\Http\Requests\ContactRequest;
use App\Http\Requests\PropertyPlanVisitRequest;
use App\KommaApp\Properties\PropertyController;
use App\KommaApp\Properties\PropertyService;
use Illuminate\Support\Facades\Redirect;

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

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

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

    /**
     * Store the request and send it by e-mail
     * Note: Validation is done in the request itself
     *
     * @param  PropertyPlanVisitRequest  $request
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function process(PropertyPlanVisitRequest $request)
    {

        $this->formService->checkManualExclusions($request);
        $this->formService->runRecaptchaValidation();

        // Store request in the database
        $this->formService->storeRequest($request);

        // Send request to the site owner
        $this->formService->sendRequest($request);

        // Send to the success route
        return Redirect::route('propertyPlanVisit.success')->with('objectId', $request->propertyId);
    }

    /**
     * Show page where we thank the user
     *
     * @return mixed
     */
    public function success()
    {
        $propertyService = new PropertyService();
        $pageController = new PropertyController($propertyService);

        $objectId = session('objectId');
        if($objectId === null) return \redirect('/');

        return $pageController->planVisit($objectId)->with('send', true);
    }
}