File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Forms/Form1Controller.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 26/09/17
* Time: 15:24
*/
namespace App\Komma\Forms;
use App\Http\Requests\Form1Request;
use App\Komma\Base\Controller;
use App\Komma\Pages\PageController;
use App\Mail\Form1Mail;
use Illuminate\Support\Facades\Mail;
final class Form1Controller extends Controller
{
/**
* @var FormService
*/
private $formService;
/**
* ContactController constructor.
* @param FormService $formService
*/
public function __construct(FormService $formService)
{
parent::__construct();
$this->formService = $formService;
$this->formService->setOrigin('form1');
}
/**
* Store the request and send it by e-mail
* Note: Validation is done in the request itself
*
* @param Form1Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function process(Form1Request $request)
{
// Store request in the database
$this->formService->storeRequest($request);
// Remove token from request (this creates and array)
Mail::send(new Form1Mail($request->except('_token', 'g-recaptcha-response')));
return redirect(localized_route('form1.success'));
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function success()
{
$pageController = new PageController();
return $pageController->show($this->links->form1->node)->with('send', true);
}
}