<?php 

class LandingController extends BaseController {

	//Contact Form
	public function getContactUsForm() {

		//Get all the data and store it inside Store Variable
		$data = Input::all();

		//Validation rules
		$rules = array (
			'name' => 'required',
			'phone'=>'required|min:8',
			'email' => 'required|email',
			'message' => 'required|min:25'
		);

		//Validate data
		$validator = Validator::make ($data, $rules);

		//If everything is correct than run passes.
		if ($validator -> passes()) {

			//Send email using Laravel send function
			Mail::send('emails.landingContact', $data, function($message) use ($data)
			{
				//email 'From' field: Get users email add and name
				$message->from($data['email'] , $data['name']);

				//email 'To' field: cahnge this to emails that you want to be notified. 
				$message
					->to('simon@icuro.com.au', 'Simon Anthonisz')
					->subject('[ICURO WEBSITE] Contact Request');
			});

			return Redirect::to('/')
            ->with('message', 'Your message was successfully sent!');

		} else {
			//return contact form with errors
			return Redirect::to('/')->withErrors($validator);
		}
	}
}