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.
Via Composer
$ composer require czim/with-blade-directive
Then add the service provider in config/app.php
:
Czim\WithBladeDirective\WithBladeDirectiveServiceProvider::class,
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.
The MIT License (MIT). Please see License File for more information.