{"id":19244835,"url":"https://github.com/conedevelopment/blade-filters","last_synced_at":"2025-05-15T18:05:27.753Z","repository":{"id":54986441,"uuid":"176592873","full_name":"conedevelopment/blade-filters","owner":"conedevelopment","description":"Use filters easily in your blade templates.","archived":false,"fork":false,"pushed_at":"2025-05-04T12:25:44.000Z","size":47,"stargazers_count":491,"open_issues_count":0,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-04T13:02:36.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pineco.de/laravel-blade-filters/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/conedevelopment.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["iamgergo","adamlaki"]}},"created_at":"2019-03-19T20:26:42.000Z","updated_at":"2025-05-04T12:25:17.000Z","dependencies_parsed_at":"2023-02-16T19:45:44.715Z","dependency_job_id":"4ac94094-fee4-4cf8-b676-ee2f22597d00","html_url":"https://github.com/conedevelopment/blade-filters","commit_stats":{"total_commits":54,"total_committers":9,"mean_commits":6.0,"dds":0.2592592592592593,"last_synced_commit":"f0b28f584df72f7ab9fe18e01e16763a4255488c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conedevelopment%2Fblade-filters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conedevelopment%2Fblade-filters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conedevelopment%2Fblade-filters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conedevelopment%2Fblade-filters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conedevelopment","download_url":"https://codeload.github.com/conedevelopment/blade-filters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394719,"owners_count":22063984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T17:25:19.896Z","updated_at":"2025-05-15T18:05:27.705Z","avatar_url":"https://github.com/conedevelopment.png","language":"PHP","funding_links":["https://github.com/sponsors/iamgergo","https://github.com/sponsors/adamlaki"],"categories":[],"sub_categories":[],"readme":"# Blade Filters\n\nUse string filters easily in Laravel Blade.\n\nIf you have any question how the package works, we suggest to read this post:\n[Laravel Blade Filters](https://pineco.de/laravel-blade-filters/).\n\n## Getting started\n\nYou can install the package with composer, running the `composer require conedevelopment/blade-filters` command.\n\n## Using the filters\n\nYou can use the filters in any of your blade templates.\n\n#### Regular usage:\n\n```php\n{{ 'john' | ucfirst }} // John\n```\n\n#### Chained usage:\n\n```php\n{{ 'john' | ucfirst | substr:0,1 }} // J\n\n{{ '1999-12-31' | date:'Y/m/d' }} // 1999/12/31\n```\n\n#### Passing non-static values:\n\n```php\n{{ $name | ucfirst | substr:0,1 }}\n\n{{ $user['name'] | ucfirst | substr:0,1 }}\n\n{{ $currentUser-\u003ename | ucfirst | substr:0,1 }}\n\n{{ getName() | ucfirst | substr:0,1 }}\n```\n\n#### Passing variables as filter parameters:\n\n```php\n$currency = 'HUF'\n\n{{ '12.75' | currency:$currency }} // HUF 12.75\n```\n\n#### Built-in Laravel functionality:\n\n```php\n{{ 'This is a title' | slug }} // this-is-a-title\n\n{{ 'This is a title' | title }} // This Is A Title\n\n{{ 'foo_bar' | studly }} // FooBar\n```\n\n### Limitations\n\n#### Echos\n\nLaravel supports three types of echos. Raw – `{!!  !!}`, regular – `{{ }}` and escaped (legacy) – `{{{ }}}`.\nFilters can be used **only with regular** echos. Also, filters **cannot be used in blade directives directly**.\n\n\u003e Why? Raw should be as it is. Forced escaping should be escaped only, without modification.\n\n#### Bitwise operators\n\nBitwise operators are allowed, but they must be wrapped in parentheses,\nsince they are using the same \"pipe operator\".\n\n```php\n{{ ('a' | 'b') | upper }} // C\n```\n\n## The Filters\n\n### About the filters\n\nFilters are string functions, that are defined in the `Pine\\BladeFilters\\BladeFilters` facade.\nIt has several reasons, that are discussed in the [Create custom filters](#create-custom-filters) section.\n\n### The available filters\n\nThe package comes with a few built-in filters, also the default Laravel string methods can be used.\n\n#### Currency\n\n```php\n{{ '17.99' | currency:'CHF' }} // CHF 17.99\n\n{{ '17.99' | currency:'€',false }} // 17.99 €\n```\n\n\u003e Passing `false` as the second parameter will align the symbol to the right.\n\n#### Date\n\n```php\n{{ '1999/12/31' | date }} // 1999-12-31\n\n{{ '1999/12/31' | date:'F j, Y' }} // December 31, 1999\n```\n\n#### Lcfirst\n\n```php\n{{ 'Árpamaláta' | lcfirst }} // árpamaláta\n```\n\n\u003e Unlike PHP's default `lcfirst()`, this filter works with multi-byte strings as well.\n\n#### Reverse\n\n```php\n{{ 'ABCDEF' | reverse }} //FEDCBA\n```\n\n#### Substr\n\n```php\n{{ 'My name is' | substr:0,2 }} // My\n\n{{ 'My name is' | substr:3 }} // name is\n```\n\n#### Trim\n\n```php\n{{ '   trim me    ' | trim }} // trim me\n```\n\n#### Ucfirst\n\n```php\n{{ 'árpamaláta' | ucfirst }} // Árpamaláta\n```\n\n\u003e Unlike PHP's default `ucfirst()`, this filter works with multi-byte strings as well.\n\n### Supported built-in Str functions\n\n- [Str::after()](https://laravel.com/docs/5.8/helpers#method-str-after)\n- [Str::before()](https://laravel.com/docs/5.8/helpers#method-str-before)\n- [Str::camel()](https://laravel.com/docs/5.8/helpers#method-str-camel)\n- [Str::finish()](https://laravel.com/docs/5.8/helpers#method-str-finish)\n- [Str::kebab()](https://laravel.com/docs/5.8/helpers#method-str-kebab)\n- [Str::limit()](https://laravel.com/docs/5.8/helpers#method-str-limit)\n- [Str::plural()](https://laravel.com/docs/5.8/helpers#method-str-plural)\n- [Str::singular()](https://laravel.com/docs/5.8/helpers#method-str-singular)\n- [Str::slug()](https://laravel.com/docs/5.8/helpers#method-str-slug)\n- [Str::snake()](https://laravel.com/docs/5.8/helpers#method-str-snake)\n- [Str::start()](https://laravel.com/docs/5.8/helpers#method-str-start)\n- [Str::studly()](https://laravel.com/docs/5.8/helpers#method-str-studly)\n- [Str::title()](https://laravel.com/docs/5.8/helpers#method-str-title)\n\n## Create custom filters\n\nAs it was mentioned before, every filter is a method that can be called through the `Pine\\BladeFilters\\BladeFilters` facade.\nIt has several reasons why is this approach better, but let's take the most important ones:\n\n- It's easy to define custom filters by extending the facade with the `BladeFilters::macro()`,\n- No extra files, autoloading or class mapping, it's enough to use any service provider to define filters,\n- By default Laravel provides a bunch of handy methods that we can use as filters.\n\n### Parameter ordering\n\nPHP is not very strict regarding to function's parameter ordering and this way it's easier to coordiante or override them.\nAlso, sometimes it happens with Laravel's string functions. It's important that only those functions can be used, that accept the parameters in the following order:\n\n1. The value to be transformed\n2. Any other parameter if needed\n\nFor example:\n\n```php\nBladeFilters::macro('filterName', function ($value, $param1 = 'default', $param2 = null) {\n    return ...;\n});\n\n{{ 'string' | filterName:1,2 }}\n```\n\n### Defining custom filters\n\nSince the filters are only methods that are defined in the `Str` facade and the `BladeFilters` class, to create filters,\nyou need to create a macro in a service provider's `boot()` method.\n\n```php\nclass AppServiceProvider extends ServiceProvider\n{\n    public function boot()\n    {\n        BladeFilters::macro('substr', function ($value, $start, $length = null) {\n            return mb_substr($value, $start, $length);\n        });\n    }\n}\n```\n\n## Contribute\n\nIf you found a bug or you have an idea connecting the package, feel free to open an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconedevelopment%2Fblade-filters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconedevelopment%2Fblade-filters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconedevelopment%2Fblade-filters/lists"}