File: D:/HostingSpaces/SBogers10/anvil.komma.pro/app/KommaApp/Forms/OfferController.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\OfferRequest;
use App\KommaApp\Pages\PageController;
use App\Mail\ContactMail;
use App\Mail\OfferMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redirect;
class OfferController extends Controller
{
/**
* @var FormService
*/
private $formService;
/**
* ContactController constructor.
* @param FormService $formService
*/
public function __construct(FormService $formService)
{
parent::__construct();
$this->formService = $formService;
$this->formService->setOrigin('offer');
}
/**
* Store the request and send it by e-mail
* Note: Validation is done in the request itself
*
* @param OfferRequest $request
*/
public function process(OfferRequest $request)
{
// Store request in the database
$this->formService->storeRequest($request);
// Remove token from request (this creates and array)
Mail::send(new OfferMail($request->except('_token')));
// Send to the success route
return Redirect::route('offer.success');
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function success()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('offer'))->with('send', true);
}
}