laravel如何显示带有确认消息的flash消息

时间:2014-11-03 12:09:26

标签: php laravel

嗨我正在尝试使用确认显示Flash消息(例如在javascript中确认警报)。我尝试下面的代码,它不显示Flash消息。请帮我解决问题。

Session::flash('flash_message', '<b>Warning!</b> Are you sure you want to delete your this event?');
        Session::flash('flash_type', 'alert-danger');
        if($event)  {
            $event->delete();
            return Redirect::to('events')->with('message', 'Event deleted successfully!');
        } else {
            Session::flash('alert-class', 'alert-danger');
            return Redirect::to('events')->with('message', 'Please try again');
        }

1 个答案:

答案 0 :(得分:1)

在您的视图中,您有删除记录的按钮,例如,您应该具有以下内容:

@if (Session::has('message'))
    <div class="alert alert-info">{{ Session::get('message') }}</div>
@endif

{{ Form::open(array('route' => array('events.destroy', $id), 'method' => 'delete')) }}
    <button type="submit" href="{{ URL::route('events.destroy', $id) }}" class="btn btn-danger btn-mini" onclick="if(!confirm('Are you sure delete this record?')){return false;};">Delete</button>
{{ Form::close() }}

在您的控制器中:

public function destroy($id)
{
    $evento = Evento::find($id);
    $evento->delete();
    Session::flash('success', 'Event delete successfully!');
    return Redirect::to('eventos');

}