PHPackages                             videni/blade-filters - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. videni/blade-filters

ActiveProject[Templating &amp; Views](/categories/templating)

videni/blade-filters
====================

Use filters easily in your blade templates.

v1.1.5(3y ago)1853MITPHPPHP ^7.2.5 | ^8.0

Since Mar 23Pushed 3y agoCompare

[ Source](https://github.com/videni/blade-filters)[ Packagist](https://packagist.org/packages/videni/blade-filters)[ RSS](/packages/videni-blade-filters/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (20)Used By (0)

Laravel Blade Filters
=====================

[](#laravel-blade-filters)

[![Laravel](https://camo.githubusercontent.com/57056a04e26fa9f4f1d1e0c5e43b905d147b0f979077245b81e370f6c4604ada/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362d2d392d726564733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/57056a04e26fa9f4f1d1e0c5e43b905d147b0f979077245b81e370f6c4604ada/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362d2d392d726564733f7374796c653d666c6174266c6f676f3d6c61726176656c)[![php](https://camo.githubusercontent.com/ff68bd27a16745b4f441f13e71906900404d2bff6818fa9e412f184a21f29177/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e322e35253743253545382e302d677265656e3f7374796c653d666c6174266c6f676f3d706870)](https://camo.githubusercontent.com/ff68bd27a16745b4f441f13e71906900404d2bff6818fa9e412f184a21f29177/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e322e35253743253545382e302d677265656e3f7374796c653d666c6174266c6f676f3d706870)[![issues](https://camo.githubusercontent.com/21ff6f621d61dcea3e04e6535d264429a8a9871571610bf297e5155fc8c228f8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f766964656e692f626c6164652d66696c74657273)](https://github.com/videni/blade-filters/issues)[![stars](https://camo.githubusercontent.com/16a92203ae194f9d19140b4a9571fd8773d06707323602d1d3af937fa87cbc92/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f766964656e692f626c6164652d66696c74657273)](https://github.com/videni/blade-filters/stargazers)[![downloads](https://camo.githubusercontent.com/4263f5e0cc49fda6676aab0d2521155bb686f00f512282c9d6e59521934dfca4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766964656e692f626c6164652d66696c746572733f7374796c653d706c6173746963267374796c653d666c6174266c6f676f3d5061636b6167697374)](https://packagist.org/packages/videni/blade-filters)

Originated from [`conedevelopment/blade-filters`](https://github.com/conedevelopment/blade-filters), but with lots of improvements, the original doesn't support named arguments and filter context, which are essential in my case. this library implements a lexer and parser to analyze filter syntax.

Because this library is almost refactored and rewritten, this package renamed as `videni/blade-filters`, but the namespace still keeps it is.

- [Laravel Blade Filters](#laravel-blade-filters)
    - [Installation](#installation)
    - [Using the filters](#using-the-filters)
        - [Regular usage:](#regular-usage)
        - [Named filter arguments](#named-filter-arguments)
        - [Chained usage:](#chained-usage)
        - [Passing non-static values:](#passing-non-static-values)
        - [Passing variables as filter parameters:](#passing-variables-as-filter-parameters)
        - [Built-in Laravel functionality:](#built-in-laravel-functionality)
        - [Limitations](#limitations)
            - [Echos](#echos)
            - [Bitwise operators](#bitwise-operators)
    - [The Filters](#the-filters)
        - [About the filters](#about-the-filters)
        - [The available filters](#the-available-filters)
            - [Currency](#currency)
            - [Date](#date)
            - [Lcfirst](#lcfirst)
            - [Reverse](#reverse)
            - [Substr](#substr)
            - [Trim](#trim)
            - [Ucfirst](#ucfirst)
        - [Supported built-in Str functions](#supported-built-in-str-functions)
    - [Custom filter](#custom-filter)
        - [Add simple custom filter](#add-simple-custom-filter)
        - [Filter provider](#filter-provider)
    - [Testing](#testing)

Installation
------------

[](#installation)

```
composer require "videni/blade-filters": "^1.0"

```

Using the filters
-----------------

[](#using-the-filters)

You can use the filters in any of your blade templates.

#### Regular usage:

[](#regular-usage)

```
{{ 'john' | ucfirst }} // John
```

#### Named filter arguments

[](#named-filter-arguments)

```
{{ 'a wonderful place' | slug:separator='_', language='en' }}

```

For slug filter which provided by `\Illuminate\Support\Str`, the first argument is the value being filtered, the second argument would be the `separator`, the third would be `language`, if a argument name doesn't not exists in the slug method, it will be simply ignored.

#### Chained usage:

[](#chained-usage)

```
{{ 'john' | ucfirst | substr:start=0,length=1 }} // J
{{ '1999-12-31' | date:format='Y/m/d' }} // 1999/12/31
```

#### Passing non-static values:

[](#passing-non-static-values)

```
{{ $name | ucfirst | substr:start=0,length=1 }}
{{ $user['name'] | ucfirst | substr:start=0,length=1 }}
{{ $currentUser->name | ucfirst | substr:start=0,length=1 }}
{{ getName() | ucfirst | substr:start=0,length=1 }}
```

#### Passing variables as filter parameters:

[](#passing-variables-as-filter-parameters)

```
$currency = 'HUF'
{{ '12.75' | currency:currency=$currency }} // HUF 12.75
```

#### Built-in Laravel functionality:

[](#built-in-laravel-functionality)

```
{{ 'This is a title' | slug }} // this-is-a-title
{{ 'This is a title' | title }} // This Is A Title
{{ 'foo_bar' | studly }} // FooBar
```

### Limitations

[](#limitations)

#### Echos

[](#echos)

Laravel supports three types of echos. Raw – `{!!  !!}`, regular – `{{ }}` and escaped (legacy) – `{{{ }}}`. Filters can be used **only with regular** echos. Also, filters **cannot be used in blade directives directly**.

> Why? Raw should be as it is. Forced escaping should be escaped only, without modification.

#### Bitwise operators

[](#bitwise-operators)

Bitwise operators are allowed, but they must be wrapped in parentheses, since they are using the same "pipe operator".

```
{{ ('a' | 'b') | upper }} // C
```

The Filters
-----------

[](#the-filters)

### About the filters

[](#about-the-filters)

All static methods from `Pine\BladeFilters\BladeFilters` and `\Illuminate\Support\Str` are provided as blade filters, it is quite simple, you can also check its source code for reference.

### The available filters

[](#the-available-filters)

The package comes with a few built-in filters, also the default Laravel string methods can be used.

#### Currency

[](#currency)

```
{{ '17.99' | currency:currency='CHF' }} // CHF 17.99
{{ '17.99' | currency:currency='€',left=false }} // 17.99 €
```

> Passing `false` as the second parameter will align the symbol to the right.

#### Date

[](#date)

```
{{ '1999/12/31' | date }} // 1999-12-31
{{ '1999/12/31' | date:format='F j, Y' }} // December 31, 1999
```

#### Lcfirst

[](#lcfirst)

```
{{ 'Árpamaláta' | lcfirst }} // árpamaláta
```

> Unlike PHP's default `lcfirst()`, this filter works with multi-byte strings as well.

#### Reverse

[](#reverse)

```
{{ 'ABCDEF' | reverse }} //FEDCBA
```

#### Substr

[](#substr)

```
{{ 'My name is' | substr:start=0,length=2 }} // My
{{ 'My name is' | substr:start=3 }} // name is
```

#### Trim

[](#trim)

```
{{ '   trim me    ' | trim }} // trim me
```

#### Ucfirst

[](#ucfirst)

```
{{ 'árpamaláta' | ucfirst }} // Árpamaláta
```

> Unlike PHP's default `ucfirst()`, this filter works with multi-byte strings as well.

### Supported built-in Str functions

[](#supported-built-in-str-functions)

- [Str::after()](https://laravel.com/docs/5.8/helpers#method-str-after)
- [Str::before()](https://laravel.com/docs/5.8/helpers#method-str-before)
- [Str::camel()](https://laravel.com/docs/5.8/helpers#method-str-camel)
- [Str::finish()](https://laravel.com/docs/5.8/helpers#method-str-finish)
- [Str::kebab()](https://laravel.com/docs/5.8/helpers#method-str-kebab)
- [Str::limit()](https://laravel.com/docs/5.8/helpers#method-str-limit)
- [Str::plural()](https://laravel.com/docs/5.8/helpers#method-str-plural)
- [Str::singular()](https://laravel.com/docs/5.8/helpers#method-str-singular)
- [Str::slug()](https://laravel.com/docs/5.8/helpers#method-str-slug)
- [Str::snake()](https://laravel.com/docs/5.8/helpers#method-str-snake)
- [Str::start()](https://laravel.com/docs/5.8/helpers#method-str-start)
- [Str::studly()](https://laravel.com/docs/5.8/helpers#method-str-studly)
- [Str::title()](https://laravel.com/docs/5.8/helpers#method-str-title)

Custom filter
-------------

[](#custom-filter)

### Add simple custom filter

[](#add-simple-custom-filter)

For the simplest case, you can add custom filter as following

```
  \Pine\BladeFilters\BladeFilters::macro('script_tag', function (string $asset,$type = 'text/javascript', $async = null, $defer = null) {
      // Your code here
    }
)

```

### Filter provider

[](#filter-provider)

You may not need this if you just want to add [simple custom filters](#add-simple-custom-filter).

The provided `StaticMacroableFilterProvider` class allows you to hook static methods and `Laravel Macroable` as Blade filters. usually, you don't need to add a `static macroable` class like `\Illuminate\Support\Str` and `\Pine\BladeFilters\BladeFilters`, you can use `StaticMacroableFilterProvider` directly, if you want to support other third party utility classes. for example,

```
$registry = new BladeFilterProviderRegistry();
$registry
    ->register(new StaticMacroableFilterProvider(\Illuminate\Support\Str::class), 10);

```

Uncommonly, your filter may be context aware, let's assume a context like this:

A filter named `cdn_url` which generates url for an asset.

```
cdn_url('assets/carousel.css');
```

the domain of the CDN will change depending on the context where the filter run, the context itself is not part of the API of our filter, which the user doesn't need to worry about. you can always pass a variable to your filter as an argument following [Pass variables to filter arguments](#pass-variables-to-filter-arguments), however, the variable must be filled by the filter's user(you or someone), this is the difference between `filter context` and `filter argument`.

filter context is a string which could be a full qualified class name or a variable in Blade view, it must have method access operator( -&gt;, :: ) suffix, an example could be the `getFilterContext` method of class `\Pine\BladeFilters\FilterProvider\StaticMacroableFilterProvider`.

```
    public function getFilterContext(): string
    {
        return sprintf('%s::', $this->class);
    }

```

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 89.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Recently: every ~1 days

Total

19

Last Release

1429d ago

Major Versions

v0.8.0 → v1.0.02022-02-19

PHP version history (5 changes)v0.1.0PHP ^7.1

v0.3.2PHP ^7.0

v0.6.0PHP ^7.2.5

v0.8.0PHP ^7.2.5 | ^8.0

v1.0.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/63229230b38bddf321e7389dfbc90c1389f7cc11e01abe3b0f372899c55ff917?d=identicon)[videni](/maintainers/videni)

---

Top Contributors

[![iamgergo](https://avatars.githubusercontent.com/u/6567179?v=4)](https://github.com/iamgergo "iamgergo (52 commits)")[![Gymnasiast](https://avatars.githubusercontent.com/u/1478678?v=4)](https://github.com/Gymnasiast "Gymnasiast (1 commits)")[![baukevdw](https://avatars.githubusercontent.com/u/6784391?v=4)](https://github.com/baukevdw "baukevdw (1 commits)")[![SeanJA](https://avatars.githubusercontent.com/u/102889?v=4)](https://github.com/SeanJA "SeanJA (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![tomsix](https://avatars.githubusercontent.com/u/60874146?v=4)](https://github.com/tomsix "tomsix (1 commits)")[![jpscharf](https://avatars.githubusercontent.com/u/1039984?v=4)](https://github.com/jpscharf "jpscharf (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/videni-blade-filters/health.svg)

```
[![Health](https://phpackages.com/badges/videni-blade-filters/health.svg)](https://phpackages.com/packages/videni-blade-filters)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k454.7k15](/packages/robsontenorio-mary)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)[konekt/html

HTML and Form Builders for the Laravel Framework

24403.2k5](/packages/konekt-html)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
