Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

czim/with-blade-directive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blade Directive: @with

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.