在您的控制器中,您可以将弹出数据传递给一个变量,并将其传递到视图中,如下所示,
控制器内部;
$output = "";
$popups = PopUp::all();
if($popups->count() > 0)
{
foreach($popups as $popup)
{
$output .=' <a href=" '.$popup->linkp.' "><img src=" '. URL::to($popup->image_path).' " style="width: 100%;"></a>';
}
json_encode($output)
然后在您的刀片视图javascript中,
@section('scripts')
<script>
$(document).ready(function(){
let popup_shown = false;
let cookies = document.cookie.split('; ');
for( let i=0; i<cookies.length; i++ ){
cookie = cookies[i].split('=');
if( cookie[0] == 'oly12_reg_ext2_popup_shown' )
popup_shown = true;
}
if( !popup_shown ){
var popup_data = '{{!! $output !!}}'
Swal.fire({ html:popup_data });
}
</script>
@endsection