烤面包机没有出现在Laravel 5.4中 [英] Toastr not showing up in laravel 5.4
问题描述
我尝试使用Toast通知,我认为我已经包括了所有内容.可以在操作后生成的页面源上看到它,但是它没有在页面上显示通知.
包括:
<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>
通话:
<script>
@if(Session::has('success'))
toastr.success("{{ Session::get('success') }}")
@endif
</script>
控制器:
$this->validate($request, [
'name' => 'required'
]);
$category = new Category; // create instance
$category->name = $request->name; // take name from form request
$category->save(); // save it to database
Session::flash('success', 'Category Has Been Created :D');
return redirect()->route('categories');
下图显示了代码已成功通过:
我最近遇到了这个问题.为了解决这个问题,我确保执行以下操作:
(您的情况可能是第4点)
1)在布局文件中链接toastr.css
和toastr.js
<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>
2)不要在标记中使用defer
属性
<script src="{{ asset('js/toastr.min.js') }}" defer></script>
应该是:
<script src="{{ asset('js/toastr.min.js') }}"></script>
3)导入 jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
4)在敬酒之前加载jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="{{ asset('js/toastr.min.js') }}"></script>
5)确保拼写,功能等正确>
I tried to use Toast notification, I think I have included everything alright. It can be seen on page source that generated after the action, but it's not showing the notification on the page.
The includes:
<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>
The call:
<script>
@if(Session::has('success'))
toastr.success("{{ Session::get('success') }}")
@endif
</script>
The controller:
$this->validate($request, [
'name' => 'required'
]);
$category = new Category; // create instance
$category->name = $request->name; // take name from form request
$category->save(); // save it to database
Session::flash('success', 'Category Has Been Created :D');
return redirect()->route('categories');
and the following image shows that code has passed with success:
I had this problem recently. To solve that, I made sure following:
(It's possibly point 4 in your case)
1) Link toastr.css
and toastr.js
in your layout file
<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>
2) Do not use defer
attribute in markup
<script src="{{ asset('js/toastr.min.js') }}" defer></script>
It should be:
<script src="{{ asset('js/toastr.min.js') }}"></script>
3) Import jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
4) Load jQuery before toastr
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="{{ asset('js/toastr.min.js') }}"></script>
5) Make sure the spellings, functions, etc. are correct
这篇关于烤面包机没有出现在Laravel 5.4中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!