2014-11-03 108 views
0

嗨,我試圖顯示帶確認的Flash消息(如在JavaScript中確認警報)。我嘗試下面的代碼,它不顯示Flash消息。請幫我解決問題。laravel如何顯示確認消息的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'); 
     } 
+0

你怎麼outputing它在模板中? – 2014-11-03 15:31:49

回答

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

}