samedi 15 août 2020

How to execute javascript in compiled view file (using View::render method)

is it possible to execute javascript code from a compiled view? i need to write some js codes inside my index.blade file to handle some events. i tried 3 way but none of them work.

Controller.

 $advertisements = Advertisement::get();
  $view = View::make('test::admin/index',['advertisements'=> $advertisements]);
  $html = $view->render();
  return $html;

index.blade.php

@push('stackscript') // NOT WORKING
<script>
  alert();
</script>
@endpush

<script>    // NOT WORKING
  alert();
</script>

@section('footer_script')  // NOT WORKING
<script>
  alert();
</script>
@endsection
<div class="row">
  @foreach ($advertisements as $advertisement)
    <div class="col-md-9">
    <div></div>
    <div></div>
    <div><img src=""></div>
  </div>
  <div class="col-md-3">
  <form id="plugin-advertisement" method="POST"  action="">
    @csrf
    @method("DELETE")
      <button class="btn bnt-sm btn-outline-danger">delete</button>
    </form>
  </div>
    @endforeach
</div>

Vue component

window.axios.get(this.url)
    .then((res) => {
    this.pluginPanel = res.data;
});

template:
<div v-if="!loading" v-html="div(pluginPanel)" />


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire