Some please help i am unable to understand the reason for this issue, when i store or content in database then it gets loads and executed on livewire component but when i am using any code then it is loading the script but not executing the script
Javascript code is not executing when using livewire component
I want to execute a code in component but the component only loads, iframe, img tag html, when i place script tag code then livewire is able to retrieve the code but script are not executed,
showads.blade.php
<div>
@if(!$isPremium)
<div id="mold-container">
{!! $loadAds !!}
</div>
@endif
</div>
ShowAds.php
<?php
namespace App\Livewire;
use App\Models\Advertisement;
use App\Models\User;
use Livewire\Component;
class ShowAds extends Component
{
public $ads_code;
public $ads;
public $loadAds;
public $isPremium = false;
public function placeholder()
{
$this->isPremium = $this->isPremium();
return view('components.placeholders.ads')->with(['ads_code' => $this->ads_code, 'isPremium' => $this->isPremium]);
}
public function mount()
{
}
public function render()
{
$this->ads = Advertisement::where('id', 1)->firstOrFail($this->ads_code);
$loadJson = json_encode($this->ads);
$unloadJson = json_decode($loadJson,true);
$this->loadAds = $unloadJson[$this->ads_code];
$this->isPremium = $this->isPremium();
return view('livewire.show-ads')->with(['loadAds' => $this->loadAds, 'isPremium' => $this->isPremium]);
}
private function isPremium(): bool
{
$user = auth()->user();
if ($user && !$user->hasActiveSubscription()) {
$user->level = 1;
$user->save();
}
return $user && $user->hasActiveSubscription();
}
}
show-app.blade.php
<main>
<div class="page-header bg-sixth">
<div class="container">
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
<div class="page-caption" style="text-align: center;">
<h1 style="color: #FFF;">APP Name</h1>
<hr style="margin-top: 0px;margin-bottom: 30px;border-top-width: 2px;">
<div class="col-lg-12 col-xl-12">
<div class="banner-frame text-center">
</div>
</div>
<x-country-holder panel="c" lazy/>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="text-center mt-3">
<livewire:ShowAds ads_code="ads_code_3" lazy/>
</div>
</div>
</div>
</main>
i am successfully getting value of ads code of front end but the ads is not assigned any space in front end hence no ads was seen, i tried to assign min-height property but that also didn't seem to work
i want to show ads code like
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- InBetween List -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-PUB_ID"
data-ad-slot="SLOT_ID"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
ads code are retrieved on front-end but javascript is not loading ads, but when i replace '<livewire:ShowAds ads_code="ads_code_3" lazy/>' directly with above adsense ad code then ads are being displayed.
any suggestion would be really helpful
Please or to participate in this conversation.