So I downloaded a fresh install of Laravel, and I'm trying to get a simple contact form to work, the contact form is at the footer, so it I included it in the master layout.
Here's what I did:
First: because I will need users I ran this command:
php artisan make:auth
Second: I edit the master page and included my form there.
Then I implemented the contact form logic, then whenever I click on send It just reloads the same page if the route group is set as [api], and if it's set as [web] it shows:
TokenMismatchException in VerifyCsrfToken.php line 67:
My Routes File:
Route::group(['middleware' => ['api']], function () {
Route::post('/', 'FormController@handleFormPost')->name('contact');
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index');
});
My FormController:
class FormController extends Controller
{
public function handleFormPost(ContactFormRequest $request)
{
$request->all();
Mail::send('emails.contactemail',
['name' => $request->get('name'),
'email' => $request->get('email'),
'msg' => $request->get('msg')], function($message)
{
$message->from('example@example.com');
$message->to('example@example.com', 'Admin')->subject('Customer Feedback');
});
return Redirect::route('/')->with('message', 'Thank you for contacting us :)');
}
}
My ContactFormRequest:
class ContactFormRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|max:120',
'email' => 'required|email|max:50',
'msg' => 'required'
];
}
}
Thank you all for your help, If I need to provide more details please inform me.