Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Traits/HasRunwayResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace StatamicRadPack\Runway\Traits;

use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Statamic\Contracts\Data\Augmented;
use Statamic\Contracts\Revisions\Revision;
Expand Down Expand Up @@ -58,7 +57,7 @@ public function scopeRunway(Builder $query)
public function scopeRunwaySearch(Builder $query, string $searchQuery)
{
$this->runwayResource()->blueprint()->fields()->all()
->filter(fn (Field $field) => Schema::hasColumn($this->getTable(), $field->handle()))
->filter(fn (Field $field) => $this->getConnection()->getSchemaBuilder()->hasColumn($this->getTable(), $field->handle()))
->reject(fn (Field $field) => $field->visibility() === 'computed')
->each(fn (Field $field) => $query->orWhere($this->getColumnForField($field->handle()), 'LIKE', '%'.$searchQuery.'%'));
}
Expand Down
43 changes: 43 additions & 0 deletions tests/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace StatamicRadPack\Runway\Tests;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Blueprint;
use Statamic\Facades\Fieldset;
use StatamicRadPack\Runway\Runway;
use StatamicRadPack\Runway\Tests\Fixtures\Models\ExternalPost;

class ResourceTest extends TestCase
{
Expand Down Expand Up @@ -301,4 +303,45 @@ public function revisions_cant_be_enabled_without_publish_states()

$this->assertFalse($resource->revisionsEnabled());
}

#[Test]
public function scope_runway_search_works_with_custom_eloquent_connection()
{
Config::set('database.connections.external', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);

Schema::connection('external')->create('external_posts', function ($table) {
$table->id();
$table->string('title');
$table->longText('body');
$table->timestamps();
});

Config::set('runway.resources.'.ExternalPost::class, []);

Runway::discoverResources();

ExternalPost::create([
'title' => 'Test External Post',
'body' => 'This is the body of the test post.',
]);

ExternalPost::create([
'title' => 'Another Post',
'body' => 'This is different content.',
]);

ExternalPost::create([
'title' => 'Something Else',
'body' => 'No matching content here.',
]);

$results = ExternalPost::query()->runwaySearch('Test External')->get();

$this->assertCount(1, $results);
$this->assertEquals('Test External Post', $results->first()->title);
}
}
20 changes: 20 additions & 0 deletions tests/__fixtures__/app/Models/ExternalPost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace StatamicRadPack\Runway\Tests\Fixtures\Models;

use Illuminate\Database\Eloquent\Model;
use StatamicRadPack\Runway\Traits\HasRunwayResource;

class ExternalPost extends Model
{
use HasRunwayResource;

protected $connection = 'external';

protected $table = 'external_posts';

protected $fillable = [
'title',
'body',
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tabs:
main:
sections:
-
fields:
-
handle: title
field:
type: text
listable: true
-
handle: body
field:
type: textarea
sidebar:
fields: { }