Flash-сообщения Laravel 5 не показывают ошибку div

Я пытался получить флэш-сообщение, информирующее пользователя о том, что его сообщение из контактной формы было успешно отправлено. Я нашел этот репозиторий Github, в котором в Laravel 5 есть "простой" способ мигать сообщения об ошибках (используя Laravel 5.2), поэтому я попробовал использовать его, но я не могу заставить его работать.

Все классы найдены, проблема здесь в том, что он не будет мигать после перенаправления.

В моем 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">&times;</button>

    {{ Session::get('flash_notification.message') }}
</div>
@endif

В моем 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('/');

});

Что я делаю не так / забыл?

РЕДАКТИРОВАТЬ Завершено 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 () {
    //
});

1 ответ

Решение

Просто измените flash:message на Session::put и убедитесь, что они находятся в группе "web" middleware.

Route::group(['middleware' => ['web']], function () {

    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('/');

    });


});
Другие вопросы по тегам