czim / with-blade-directive
@with blade directive
Installs: 2 791
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- orchestra/testbench: ~3.0
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
This package is auto-updated.
Last update: 2021-05-19 21:44:57 UTC
README
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.