statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/addons/rad-pack/runway
MIT License
112 stars 47 forks source link

Can't use `url` when indexing Runway models #625

Open aaronbushnell opened 2 days ago

aaronbushnell commented 2 days ago

Description

I'm getting App\Models\Post::url must return a relationship instance when trying to index Runway models that use url within the fields configuration:

'posts' => [
    'driver' => 'local',
    'searchables' => ['runway:post'],
    'fields' => ['title', 'url'],
],

However, url does work when including it in a Runway loop:

{{ runway:post }}
    {{ url }}
{{ /runway:post }}

Steps to reproduce

  1. Create a Laravel model and connect it to Runway (ensuring it has routing setup, too)
  2. Setup the example search config above
  3. Attempt to update this index using php please search:update posts

Environment

Environment Application Name: OBFUSCATED Laravel Version: 11.29.0 PHP Version: 8.3.12 Composer Version: 2.7.7 Environment: local Debug Mode: ENABLED URL: post-statamic.test Maintenance Mode: OFF Timezone: America/Indiana/Indianapolis Locale: en

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

Drivers Broadcasting: log Cache: file Database: sqlite Logs: stack / single Mail: log Queue: sync Session: file

Statamic Addons: 11 Sites: 1 Stache Watcher: Enabled (auto) Static Caching: Disabled Version: 5.33.1 PRO

Statamic Addons rias/statamic-redirect: 3.8.1 statamic-rad-pack/runway: 7.11.0 statamic/seo-pro: 6.3.0 stillat/relationships: 2.2.1 trendyminds/guide: dev-main trendyminds/link: dev-main trendyminds/nerf: 1.2.0 trendyminds/orbit-statamic: 2.0.0 trendyminds/statamic-geocoder: 2.0.2 trendyminds/statamic-palette: 1.2.1 trendyminds/tip: 1.0.0

ryanmitchell commented 2 days ago

Can you add the full stack trace?

aaronbushnell commented 2 days ago

Definitely! Here you go—

App\Models\Post::url must return a relationship instance, but "null" was returned. Was the "return" keyword used?

at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:611
  607▕         $relation = $this->$method();
  608▕ 
  609▕         if (! $relation instanceof Relation) {
  610▕             if (is_null($relation)) {
➜ 611▕                 throw new LogicException(sprintf(
  612▕                     '%s::%s must return a relationship instance, but "null" was returned. Was the "return" keyword used?', static::class, $method
  613▕                 ));
  614▕             }
  615▕ 

    +29 vendor frames 

30  please:18
    Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput))