Wingman for Craft CMS

Wingman is a Craft 6 plugin. Craft 6 is still in beta, and so is Wingman (6.0.0-beta.1) — try it on staging first and use caution on production sites.

Templates (Twig and Blade)

Craft 6 renders .twig and .blade.php templates alike, and everything here works in both.

Querying

Each model gets a template query named after the plural of its handle, camel-cased: Customer → craft.customers(), WingmanInvoice → craft.wingmanInvoices().

{% for customer in craft.customers().orderBy('name').all() %}
  <li>{{ customer }} — {{ customer.company }}</li>
{% endfor %}
@foreach ($craft->customers()->orderBy('name')->all() as $customer)
  <li>{{ $customer }} — {{ $customer->company }}</li>
@endforeach

Model columns read as element properties (customer.company). Printing the element prints its label column. customer.getModel() returns the Eloquent model itself.

From a model to its element

{% set element = wingman.element(order.customer) %}
{{ element ? element.url }}
@php($element = $wingman->element($order->customer))

wingman.element() returns null for anything that isn't a registered model's row with an element.

Related entries (Pro)

{# Entries relating to this customer through the `customers` field #}
{% for entry in wingman.relatedEntries(customer, 'customers').all() %}…{% endfor %}

{# Through any Wingman field, from a model or its element #}
{{ wingman.relatedEntries(customer.getModel()).count() }}

{# Other element types, by reference handle #}
{% set photos = wingman.related(customer, 'asset', 'photos').all() %}
@foreach ($wingman->relatedEntries($customer, 'customers')->all() as $entry) … @endforeach

These return ordinary element queries for the current site, with Craft's normal status rules. A field handle that isn't a relation field to that model is an error, not an empty result.

More plugins

Pairs well with Wingman