PHPackages                             djl997/blade-shortcuts - 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. djl997/blade-shortcuts

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

djl997/blade-shortcuts
======================

Blade Shortcuts is a library of handy Laravel Blade Directives.

1.10.0(8mo ago)4197311MITPHPPHP ^8.0CI passing

Since Nov 1Pushed 8mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (24)Used By (1)

Blade Shortcuts
===============

[](#blade-shortcuts)

[![Latest Version on Packagist](https://camo.githubusercontent.com/043c7ae263f2c8b2fa2dcef2e35b94b9efc95f5b9ce911f34494825159597172/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646a6c3939372f626c6164652d73686f7274637574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/djl997/blade-shortcuts)[![Total Downloads](https://camo.githubusercontent.com/6fe810098488dd85c326dc0d023db178e71bddac924a5cc5eedf0948c08a2a78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646a6c3939372f626c6164652d73686f7274637574732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/djl997/blade-shortcuts)[![Build Status](https://camo.githubusercontent.com/32403fa19d056e84b94e4afd6ffbff38670dda5aa0c9550b5757780351a8394d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646a6c3939372f626c6164652d73686f7274637574732f706870756e69742e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265266272616e63683d6d61696e)](https://camo.githubusercontent.com/32403fa19d056e84b94e4afd6ffbff38670dda5aa0c9550b5757780351a8394d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646a6c3939372f626c6164652d73686f7274637574732f706870756e69742e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265266272616e63683d6d61696e)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Blade Shortcuts is a library of clever Blade Directives as listed below. The goal is to have less repetitive (base) logic in your Blade Views, overall shorter code and better readability.

Requirements
------------

[](#requirements)

Blade Shortcuts requires PHP 8+ and Laravel 6+.

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

[](#installation)

You can install the package via composer:

```
composer require djl997/blade-shortcuts
```

Usage
-----

[](#usage)

After installation, all directives should be usable immediately. If something goes wrong at first use or after an update, `php artisan view:clear` should clear the issue.

Contents
--------

[](#contents)

- [App Name](#app-name)
- [Arrays](#arrays)
- [Boolean](#boolean)
- [Config](#config)
- [Dates](#dates)
    - date, datetime, time, year, month, day
    - [dayOf](#day-of-week-day-of-month-day-of-year)
        - dayOfWeek
        - dayOfMonth
        - dayOfYear
    - [cascades](#carbon-cascades)
        - cascadeFromMinutes
        - cascadeFromHours
        - cascadeFromDays
        - cascadeFromWeeks
        - cascadeFromMonths
- [Filesizes](#filesize)
- [Fluent Strings](#fluent-strings)
- [Money](#money)
- [Nl2br](#nl2br)
- [Not empty](#not-empty-inverse-of-empty)
- [Not isset](#not-isset-inverse-of-isset)
- [Percentage](#percentage)

### App Name

[](#app-name)

```
@appname
```

### Boolean

[](#boolean)

```
@boolean(true)
@boolean(false)
```

### Config

[](#config)

```
@config('config-file.key')
```

### Dates

[](#dates)

Automatically translate dates in the correct localized format (currently only EN, NL, DE, ES supported).

```
@date()
@date(time())
@date(date('Y-m-d'))
```

Other options:

```
@date(now()->subHours(20))
@date(now()->subHours(20), 'dateOrDiff')
@date(now()->subWeek())
@date(now()->subWeek(), 'dateOrDiff')
```

> If the time difference is more than 23 hours, ‘dateOrDiff’ will automatically show the date in a localized format instead of ‘x time ago’ or ‘in x time’. You can adjust this threshold in the config file: `php artisan vendor:publish --tag=blade-shortcuts-config`.

Try shortcuts for datetime, time, year, month or day (also in the correct localized format):

```
@datetime
@time
@year
@month
@day
```

You even can add a custom date to datetime, time, year, month or day, for example:

```
@day(now())
@year('2024-02-08')
```

#### Day of Week, Day of Month, Day of Year

[](#day-of-week-day-of-month-day-of-year)

In some cases you need the *x* day of week, month or year.

```
@dayOfYear
@dayOfMonth
@dayOfWeek
```

Or generate it based on a value:

```
@dayOfWeek('2024-06-25')
@dayOfWeek(now()->subDay())
@dayOfYear($user->updated_at)
```

#### Carbon Cascades

[](#carbon-cascades)

If you want to display a certain amount of time in human readable format, try out the new cascade directives. For example, convert 125 minutes to a readable format:

```
@cascadeFromMinutes(125)
@cascadeFromHours(146)
```

##### Change the time unit

[](#change-the-time-unit)

If you set the time unit (2nd item in the array), the cascade will cascade max to the given unit. In the example below, we have 1530 minutes, divided into hours of 60 minutes:

```
@cascadeFromMinutes(1530)
@cascadeFromMinutes([1530, ['hour' => 60]])
```

##### CarbonInterval

[](#carboninterval)

The example above also means you can tweak the [CarbonInterval](https://carbon.nesbot.com/docs/#api-interval). Suppose you have a project that requires 125 hours of work and you can allocate 30 hours per day for it. How many days will it take to complete the project? We use the `@cascadeFromHours` directive to calculate this value:

```
@cascadeFromHours([125, ['day' => 30]])
```

### Filesize

[](#filesize)

```
@filesize(2145)
@filesizemb(124588)
@filesizegb(1198466000)
```

### nl2br

[](#nl2br)

How to display input from a `textarea` in a read-only situation? Maybe you use `{!! $comment !!}` to get unexcaped data. In this way, you loose the XSS prevention, so maybe you sacrifice the newlines if the risk is too high. Now, that is no longer necessary: use the `@nl2br` directive.

```
@nl2br('Your view will show newlines.\n\n Very intuitive.')

@nl2br('Your possible unsafe HTML code alert('Hello world')\n will not execute.')

```

### Not Empty, inverse of @empty

[](#not-empty-inverse-of-empty)

```
@notEmpty(1)
    I'm not empty.
@endNotEmpty
```

### Not set, inverse of @isset

[](#not-set-inverse-of-isset)

```
@notSet($notSetVariable)
    I'm not set.
@endNotSet
```

### Percentages

[](#percentages)

```
@percentage(1)
@percentage(0.055)
@percentage(100)
@percentage(50)
@percentage(0.5)
@percentage(0.505)
@percentage(-5)
```

### Simple Money

[](#simple-money)

```
@simpleMoney()
@simpleMoney(.99)
@simpleMoney(112327.20)
@simpleMoney(112327.20, 'JPY')
@simpleMoney(112327.20, 'USD', 'es')
```

### Helpers

[](#helpers)

#### Arrays

[](#arrays)

```
