czim/with-blade-directive

This package is abandoned and no longer maintained. No replacement package was suggested.

@with blade directive

1.1.0 2016-09-27 19:09 UTC

This package is auto-updated.

Last update: 2021-05-19 21:44:57 UTC


README

Software License

A simple blade directive to help clean up your views.

Instead of doing this elaborate jig:

    <tr>
        <td>{{ $model->relation->method()->object->first_name }}</td>
        <td>{{ $model->relation->method()->object->first_name }}</td>
        <td>{{ $model->relation->method()->object->email }}</td>
    </tr>

You can clean it up like this:

    @with($model->relation->method()->object as $object)

    <tr>
        <td>{{ $object->first_name }}</td>
        <td>{{ $object->first_name }}</td>
        <td>{{ $object->email }}</td>
    </tr>

All this does is assign an expression to a variable.

Install

Via Composer

$ composer require czim/with-blade-directive

Then add the service provider in config/app.php:

Czim\WithBladeDirective\WithBladeDirectiveServiceProvider::class,

Usage

The @with directive supports two formats:

    @with(any_expression($you * $want) as $variableName)

    @with('variableName', any_expression($you * $want))

These have exactly the same result.

Credits

License

The MIT License (MIT). Please see License File for more information.