Reputation: 538
hi i'm trying to display flash message with confirm(like confirm alert in javascript) . i m trying this below code its does not display flash message. please help me to resolve the problem.
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');
}
Upvotes: 0
Views: 3863
Reputation: 90
In your view, where you have the button to delete a record for example you should have something like this:
@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() }}
In your controller:
public function destroy($id)
{
$evento = Evento::find($id);
$evento->delete();
Session::flash('success', 'Event delete successfully!');
return Redirect::to('eventos');
}
Upvotes: 1