Javascript laravel toastr js通知显示在每个页面上
在我的控制器中:Javascript laravel toastr js通知显示在每个页面上,javascript,php,jquery,laravel,notifications,Javascript,Php,Jquery,Laravel,Notifications,在我的控制器中: public function showFreelancers(Request $request) { $authUser = Auth::user(); session()->put('success','Item created successfully.'); return view('freelancer/index',compact('authUser')); } 我只有一个session
public function showFreelancers(Request $request)
{
$authUser = Auth::user();
session()->put('success','Item created successfully.');
return view('freelancer/index',compact('authUser'));
}
我只有一个session()->put('success','Item created successfully')代码>在我的整个控制器中
我的布局页面上有下面的代码。下面是所有js文件
<script>
@if(Session::has('success'))
toastr.success("{{ Session::get('success') }}");
@endif
@if(Session::has('info'))
toastr.info("{{ Session::get('info') }}");
@endif
@if(Session::has('warning'))
toastr.warning("{{ Session::get('warning') }}");
@endif
@if(Session::has('error'))
toastr.error("{{ Session::get('error') }}");
@endif
</script>
@if(会话::has('success'))
toastr.success(“{Session::get('success')}”);
@恩迪夫
@if(会话::has('info'))
toastr.info(“{Session::get('info')}”);
@恩迪夫
@if(会话::has('warning'))
toastr.warning(“{Session::get('warning')}”);
@恩迪夫
@if(Session::has('error'))
错误(“{Session::get('error')}”);
@恩迪夫
当我点击Route::get('/','FreelancerController@showFreelancers')->name('freegorindex')代码>我收到消息,这是好的!但当我打开另一条路线时,我得到了完全相同的通知
我做错了什么?您实际上是在将它永久性地推到会话中,而不是暂时性地推到会话中。你可以用
session()->flash('key', 'value')
现在它只会在下一页而不是每一页上闪烁。将会话更改为flash()后,您还需要清除会话。