javascript - Laravel flash message can't close using close button and can't close by itself in a while - Stack O

Flash message stays in there and can't close by itself and button close. I use bootstrap and js fo

Flash message stays in there and can't close by itself and button close. I use bootstrap and js for build flash message. This my code.

Controller, i put before redirect line.

Session::flash('flash_message', 'It has been saved!');

also, i have written use Session on Controller.

I made flash_message.blase.php

@if(Session::has('flash_message'))
  <div class="alert alert-success {{ Session::has('penting') ? 'alert-important' : '' }}">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    {{ Session::get('flash_message') }}
  </div>
@endif

flash_message.blade.php has been included on index.

This the js code:

$('div.alert').not('.alert-important').delay(3000).slideUp(300);

js code has been written as script on my main template.

Why can't those work? How to fix it?

Flash message stays in there and can't close by itself and button close. I use bootstrap and js for build flash message. This my code.

Controller, i put before redirect line.

Session::flash('flash_message', 'It has been saved!');

also, i have written use Session on Controller.

I made flash_message.blase.php

@if(Session::has('flash_message'))
  <div class="alert alert-success {{ Session::has('penting') ? 'alert-important' : '' }}">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    {{ Session::get('flash_message') }}
  </div>
@endif

flash_message.blade.php has been included on index.

This the js code:

$('div.alert').not('.alert-important').delay(3000).slideUp(300);

js code has been written as script on my main template.

Why can't those work? How to fix it?

Share Improve this question asked Jul 12, 2018 at 3:07 Kyera NunaKyera Nuna 451 silver badge11 bronze badges 6
  • So the alert shows up, but doesn't disappear when you ckick the button, is that it? – Mav Commented Jul 12, 2018 at 3:10
  • Yeah, That is right. What happens? How do make it work? – Kyera Nuna Commented Jul 12, 2018 at 3:11
  • Are you loading the bootstrap javascript plugin? See: getbootstrap./docs/4.0/ponents/alerts/#dismissing – Mike Commented Jul 12, 2018 at 3:40
  • I've tried a few possibilities, it's still no change. still can't close. – Kyera Nuna Commented Jul 12, 2018 at 4:20
  • I pretty sure that you did not load bootstrap javascript plugin. Check your page in using developer tool, maybe some error logged in your console. – Ts8060 Commented Jul 12, 2018 at 4:23
 |  Show 1 more ment

2 Answers 2

Reset to default 7

Try this

@if (session()->has('success'))
    <div class="alert alert-dismissable alert-success">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        <strong>
            {!! session()->get('success') !!}
        </strong>
    </div>
@endif

This is what I use, without any issues.

@if(isset($errors))
    @if(count($errors) >0 )
        @foreach($errors->all() as $error)
            <div class="alert alert-danger alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                {{$error}}
            </div>
        @endforeach
    @endif
@endif
@if(session('success'))
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        {{session('success')}}
    </div>
@endif

@if(session('error'))
    <div class="alert alert-error alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        {{session('error')}}
    </div>
@endif

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742287066a4415508.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信