0

I have a simple section in which I would like to use jquery, Here is what I have so far

@extends('layouts.app', ['activePage' => 'user-management', 'titlePage' => __('User Management')])

@section('content')
  <div class="content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">

            <h1> TESTING inline JS </h1>
        </div>
      </div>
    </div>
  </div>
@endsection

@section('script')

<script type="text/javascript">

      alert('Imagination');

</script>
@endsection

When I run my app there is no alert just text Testing inline js

What is wrong with my code?

2 Answers 2

5

So I assume that in your layouts/app.blade.php you are yielding the script section?

@yield('script')

Then you need to show the alert once the page loads.

So if you use jQuery as you say, add this code:

$(function() { // after the page has loaded..
    alert('Imagination');
});

Sign up to request clarification or add additional context in comments.

Comments

0

The anwser above is correct, that you are missing the @yield('script') on your layouts.app. However, a better practice would be, instead of using a section, is to use @push('script') & @endpush then in your template to use @stack('script').

The advantage over using sections is that if you have multiple templates being rendered, the scrips for each of them will 'stack' where you use the stack in your main template.

You can see the docs on it here: https://laravel.com/docs/5.8/blade#stacks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.