简体   繁体   中英

laravel how to display flash message with confirm message

hi i'm trying to display flash message with confirm(like confirm alert in javascript) . im 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');
        }

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM