Juliatzin
Juliatzin

Reputation: 19695

Check request URL in laravel

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!

Upvotes: 0

Views: 8527

Answers (2)

clean_coding
clean_coding

Reputation: 1166

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') !!}
}

Upvotes: 4

Petyo Tsonev
Petyo Tsonev

Reputation: 587

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.

Upvotes: 0

Related Questions