N
N
Northern Lights2020-04-26 03:33:04
Laravel
Northern Lights, 2020-04-26 03:33:04

How to add js path to stack from PHP?

The framework allows you to add some js from the template to the stack:

@push('scripts')
    <script src="...."></script>
@endpush


How can the same be done from PHP?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2020-04-26
@php666

The trait used in the VIew facade contains the required method:
https://github.com/illuminate/view/blob/99fa4b3513...
As a result, you can add scripts to your tech from the controller or other place through:

\Illuminate\Support\Facades\View::startPush('scripts', script('./path/to/script.js'));

Just keep in mind that you need stopPush() to work correctly, ob_get_clean() happens there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question