Giter VIP home page Giter VIP logo

active-state's Introduction

Active State

Packagist license Travis Scrutinizer

This package helps you check if a given link matches the current URL, route or query string. This is especially useful in sidebars.

History
This package was originally a fork from pyaesone17/active-state. To fix issue #8, I rewrote entirely the package.

Example

Basically you would do like this:

<li class="sidebar {{ Request::is('post') ? 'active' : 'no' }} ">Post</li>
<li class="sidebar {{ Request::is('page') ? 'active' : 'no' }} ">Page</li>

With this package, you can make it shorter:

<li class="sidebar {{ active_url_is('post') }} ">Post</li>
<li class="sidebar {{ active_url_is('page') }} ">Page</li>

Or, if you prefer to check the route:

<li class="sidebar {{ active_route_in('users.list') }}">Users list</li>
<li class="sidebar {{ active_route_in('groups.list') }}">Groups list</li>

Keywords: route, url, query, menu, link, request, laravel, active

TL;DR

Maybe you just need the cheatsheet?

Table of contents

  1. Quickstart
  2. Installation
  3. Usage
  4. Blade directives
  5. Additional features
  6. Cheatsheet

Quickstart

Install with Composer

composer require arcesilas/active-state:^2.0

Use it in your views

Check current URL is foo/bar:

<li class="menu-item {{ Active::ifUrlIs('foo/bar') }}">Foo: Bar</li>

will render:

<li class="menu-item active">Foo: Bar</li>

if the current URL is actually foo/bar.

Check route name is posts:

<a class="nav-link {{ Active::ifRouteIn('posts') }}" href="{{ route('posts') }}">

Check route name is posts and slug parameter is a given value:

<a class="nav-link {{Active::ifRouteIs('posts.category', ['slug' => $category->slug])}}" href="{{ route('posts.category', $category->slug) }}">

Check query string contains argument foo with value bar:

<a class="nav-link {{Active::ifQueryHas('videos.category', ['slug' => $category->slug])}}" href="{{ route('videos.category', $category->slug) }}">

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.