2017 © Pedro Peláez
 

library active

Laravel helper for recognising the current route, controller and action

image

watson/active

Laravel helper for recognising the current route, controller and action

  • Saturday, August 26, 2017
  • by dwightwatson
  • Repository
  • 6 Watchers
  • 156 Stars
  • 83,398 Installations
  • PHP
  • 9 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 23 Versions
  • 13 % Grown

The README.md

Active for Laravel

Build Status Total Downloads Latest Stable Version Latest Unstable Version License Buy us a tree, (*1)

Active is a helper package for Laravel that makes it easy to recognize the current path or route, useful for adding 'active' classes (like those used in the Boostrap framework) and performing other actions only when a certain route is active. It also includes helpers for retrieving the current controller and action names., (*2)

Installation

First, simply require the package through Composer., (*3)

composer require watson/active

Using Laravel 5.1? The latest version of the package that will work for you is 2.0.4., (*4)

Next, add the service provider in your config/app.php file., (*5)

Watson\Active\ActiveServiceProvider::class, (*6)

If you'd like to use the Facade instead of the helper functions, add it to the aliases array., (*7)

'Active' => Watson\Active\Facades\Active::class, (*8)

Using Active

Helper functions

Active ships with a couple of helper functions which make it easy to use without the facade or creating an instance of your own., (*9)

active()
is_active()

Using active()

You pass an array of routes or paths you want to see are the current page, and if any match this function will return the string active, for Bootstrap. Alternatively, you can pass a custom return string as the second argument., (*10)

active(['login', 'users/*', 'posts.*', 'pages.contact']); // Returns 'active' if the current route matches any path or route name.

active(['login', 'logout'], 'active-class'); // Returns 'active-class' if the current route is 'login' or 'logout'.

active(['login', 'logout'], 'active-class', 'fallback-class'); // Returns 'fallback-class' if the current route is not 'login' or 'logout'.

In the first example, the function will return the string active if the current path is login, starts with users/ or if the name of the current route is posts.create., (*11)

Do note that a number of argument types are provided: you can use a path string, you can use a path string with a wildcard (using the *) and you can also use named routes., (*12)

You can use this function with your links to give them an active state., (*13)

<a href="{{ route('posts.index') }}" class="{{ active('posts.index') }}">All posts</a>

You can also provide certain paths or routes to be exluded when being considered., (*14)

active(['pages/*', 'not:pages/contact'])

active(['pages.*', 'not:pages.contact'])

Using is_active()

This works much the same as active(), you can pass the paths and routes to it but instead it will return a boolean if the current page matches., (*15)

@if (is_active('posts/*'))
    You're looking at a blog post!
@endif

Additional helpers

Two additional functions are provided to get the current controller and action, if your routing is being handled by a controller for a request. These functions will return the lowercase controller/action name, without the method of the request. Here is an example for a request that is routed to `FooController@getBar':, (*16)

$controller = controller_name(); // foo

$action = action_name(); // bar

Licence

Active for Laravel is 100% free and open-source, under the MIT license. Use it however you want., (*17)

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats., (*18)

The Versions

26/08 2017

dev-master

9999999-dev

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

26/08 2017

2.0.6

2.0.6.0

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

09/07 2017

2.0.5

2.0.5.0

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

07/05 2017

2.0.4

2.0.4.0

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

20/11 2015

2.0.3

2.0.3.0

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

20/11 2015

2.0.2

2.0.2.0

Laravel helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

20/11 2015

2.0.1

2.0.1.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

20/11 2015

2.0.0

2.0.0.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

17/03 2015

1.3.1

1.3.1.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

17/03 2015

1.3.0

1.3.0.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

24/07 2014

1.2.4

1.2.4.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

18/07 2014

1.2.3

1.2.3.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

10/07 2014

1.2.2

1.2.2.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

03/07 2014

1.2.1

1.2.1.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

27/05 2014

1.2.0

1.2.0.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

27/05 2014

1.1.1

1.1.1.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

27/05 2014

1.1.0

1.1.0.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

14/03 2014

1.0.5

1.0.5.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

14/03 2014

1.0.4

1.0.4.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

11/03 2014

1.0.3

1.0.3.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

07/03 2014

1.0.2

1.0.2.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

06/03 2014

1.0.1

1.0.1.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active

06/03 2014

1.0.0

1.0.0.0

Laravel 4 helper for recognising the current route, controller and action

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dwight Watson

laravel routing active