File: D:/HostingSpaces/ASmits/kemi.nl/app/KommaApp/Forms/ContactController.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\KommaApp\Pages\PageController;
use Illuminate\Support\Facades\Redirect;
class ContactController extends Controller
{
/**
* @var FormService
*/
private $formService;
/**
* ContactController constructor.
* @param FormService $formService
*/
public function __construct(FormService $formService)
{
parent::__construct();
$this->formService = $formService;
$this->formService->setOrigin('contact');
}
/**
* Store the request and send it by e-mail
* Note: Validation is done in the request itself
*
* @param ContactRequest $request
*/
public function process(ContactRequest $request)
{
if (!$request->has('honey') || !empty($request->get('honey'))) {
return back()->withInput($request->all());
}
// 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('contact.success');
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function success()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('contact'))->with('send', true);
}
}