0

In dashboard.blade.php, I manage js library links.

So, as I don't want to include all libs in all pages, I do it like that:

@if (Request::is("mail/create"))
        {!! Html::script('js/plugins/ui/nicescroll.min.js') !!}
        {!! Html::script('js/sidebar_detached_sticky_custom.js') !!}
@endif

for each page or group of pages.

Thing is when I edit an item, I my URL have this format:

http://laravel.dev:8000/mail/1/edit

And as 1 is the shop Id and vary, my method doesn't work anymore....

Any way to fix my issue or to do it better???

Tx!

2 Answers 2

4

You can use a route name instead, then you can do it like this:

@if (Request::route()->getName() == "mail_edit") {
    {!! Html::script('js/plugins/ui/nicescroll.min.js') !!}
    {!! Html::script('js/sidebar_detached_sticky_custom.js') !!}
}

Here's the laravel docs for named routes: https://laravel.com/docs/5.1/routing#named-routes

Or you can do this:

@if (strpos(Request::url(),'mail') !== false && strpos(Request::url(),'edit') !== false) {
    {!! Html::script('js/plugins/ui/nicescroll.min.js') !!}
    {!! Html::script('js/sidebar_detached_sticky_custom.js') !!}
}
Sign up to request clarification or add additional context in comments.

1 Comment

tx for your help! second options worked! add this for the first answer : laravel.com/docs/5.1/routing#named-routes
0

you should include the js libs in your main template ( this one which you extend) if you @extend(main) add the libs in the header of the main template, then you will not need to add it on every page.

1 Comment

that's what I do, but I don't want to include all my js in all my pages. You write once, but it is included in all pages, this is no good, it get a lot of conflicts

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.