statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/runway
MIT License
107 stars 43 forks source link

Accessing a runway model from a non-runway collection #447

Closed swilla closed 4 months ago

swilla commented 4 months ago

Description

I'm trying to access a runway belongsTo relation from a non-runway Collection. I can see the "ID" if the belongsTo relation, but I cannot access any of the properties on that model.

Steps to reproduce

Setup a Collection that has a belongsTo field to a runway model.

tabs:
  main:
    display: Main
    sections:
      -
        fields:
          -
            handle: title
            field:
              type: text
              required: true
              validate:
                - required
          -
            handle: content
            field:
              type: markdown
              localizable: true
          -
            handle: soothsayer
            field:
              max_items: 1
              mode: default
              resource: soothsayer
              create: true
              type: belongs_to
              display: Soothsayer
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false
              relationship_name: soothsayer
              title_format: Soothsayer
              with:
                - user
              validate:
                - required
          -
            handle: tarot_card
            field:
              options:
                tarot_card_1: 'Card 1'
                tarot_card_2: 'Card 2'
                tarot_card_3: 'Card 3'
                tarot_card_4: 'Card 4'
              taggable: false
              push_tags: false
              multiple: false
              clearable: false
              searchable: true
              cast_booleans: false
              type: select
              display: 'Tarot Card'
              listable: hidden
              instructions_position: above
              visibility: visible
              replicator_preview: true
              hide_display: false
  sidebar:
    display: Sidebar
    sections:
      -
        fields:
          -
            handle: slug
            field:
              type: slug
              localizable: true
              validate: 'max:200'
title: 'Featured Soothsayer'

Model Config:

    'resources' => [
        \App\Models\Soothsayer::class => [
            'name' => 'Soothsayers',
            'blueprint' => 'soothsayer',
            'title_field' => 'name',
            'read_only' => true,
        ],
    ],
 {{ collection:featured_soothsayers limit="3" as="featured" with="soothsayer" }}
                        {{ featured | dump }}
                        <div id="card-{{ count }}" x-show="card{{ count }}" class="flex flex-row justify-center"
                            x-transition:enter.duration.1000ms>
                            {{ partial:components.featured_soothsayer img="assets/{{tarot_card}}.png" name="{{title}}" bio="{{content}}" photo="{{featured:soothsayer:first_photo}}" }}
                       </div>
                    {{ /collection:featured_soothsayers }}

image

Environment

Environment
Application Name: Soothsayers
Laravel Version: 10.44.0
PHP Version: 8.2.16
Composer Version: 2.7.1
Environment: local
Debug Mode: ENABLED
URL: soothsayers.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Filament
Packages: filament, forms, notifications, support, tables
Version: v3.2.34
Views: NOT PUBLISHED

Livewire
Livewire: v3.4.4

Statamic
Addons: 2
Antlers: runtime
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.49.0 PRO

Statamic Addons
statamic-rad-pack/runway: 6.3.0
tapp/filamentlink: dev-main
duncanmcclean commented 4 months ago

The screenshot of the dump is just showing the entry's data, which will just be the raw ID. I'm guessing you've tried something like this?

{{ soothsayer:title }}
swilla commented 4 months ago

Ok, I figured this out. I was accessing a property that didn't exist on the runway model yet. I addition, the as piece was messing things up. Here is the final version that works:

{{ collection:featured_soothsayers limit="3" }}
<div 
    id="card-{{ count }}" 
    x-show="card{{ count }}" 
    class="flex flex-row justify-center"
    x-transition:enter.duration.1000ms
>
        {{ partial:components/featured_soothsayer :img="tarot_card" :name="title" :bio="content" :photo="soothsayer:profile_picture" }}
</div>
 {{ /collection:featured_soothsayers }}