簡體   English   中英

Laravel 5 laracasts Flash消息未顯示錯誤div

[英]Laravel 5 laracasts flash messaging not showing error div

我一直在嘗試獲取即時消息,讓用戶知道他們從聯系表單中發送的消息已成功發送,我發現了這個Github Repo ,其中在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 () {
    //
});

只需將flash:message更改為Session :: put並確保它們在“ Web”中間件組下即可。

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

    });


});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM