I've been trying to get a flash message letting the user know that their message from the contact form has successfully been sent, I found This Github Repo in which there's an "easy" way of flashing error messages in Laravel 5 (I'm using Laravel 5.2) so I went on an tried using it, but I can't seem to get it to work.
The classes are all being found, the problem here is that it won't flash after I redirect.
In my master.blade.php
@if (Session::has('flash_notification.message'))
<div class="alert alert-{{ Session::get('flash_notification.level') }}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('flash_notification.message') }}
</div>
@endif
In my routes.php
Route::post('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('email@provider', 'Learning Laravel!');
$message->to('email@provider')->subject('Learning Laravel test email');
});
Flash::message('Thank you for contacting us, we will get back to you as soon as possible.');
return Redirect::to('/');
});
What am I doing wrong / forgetting?
EDIT Complete routes.php
<?php
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('index');
});
Route::post('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('email@provider', 'Learning Laravel!');
$message->to('email@provider')->subject('Learning Laravel test email');
});
Session::put('flash_notification.message', 'Thank you for contacting us, we will get back to you as soon as possible.');
return Redirect::to('/');
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
//
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire