Skip to content

Commit

Permalink
[5.x] Fix blueprint error when publishing Eloquent Driver migrations (#…
Browse files Browse the repository at this point in the history
…320)

* Fix blueprint error when publishing Eloquent Driver migrations

* Fix styling

* Re-work the fix

---------

Co-authored-by: duncanmcclean <duncanmcclean@users.noreply.github.com>
  • Loading branch information
duncanmcclean and duncanmcclean authored Sep 5, 2023
1 parent 0e031d1 commit 2f2c32a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Routing/RoutingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Statamic\Data\ContainsSupplementalData;
use Statamic\Data\HasAugmentedData;

class RoutingModel implements Responsable, Augmentable
class RoutingModel implements Augmentable, Responsable
{
use ContainsSupplementalData, HasAugmentedData;

Expand Down
15 changes: 12 additions & 3 deletions src/Runway.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ public static function discoverResources(): self
if (! in_array(Traits\HasRunwayResource::class, class_uses_recursive($model))) {
throw new \Exception(__('The HasRunwayResource trait is missing from the [:model] model.', ['model' => $model]));
}

if (! isset($config['blueprint'])) {
throw new \Exception(__('The [:model] model is missing a blueprint.', ['model' => $model]));
}

if (is_string($config['blueprint'])) {
$blueprint = Blueprint::find($config['blueprint']);
try {
$blueprint = Blueprint::find($config['blueprint']);
} catch (\Exception $e) {
// If we're running in a console & the blueprint doesn't exist, let's ignore the resource.
// https://github.com/duncanmcclean/runway/pull/320
if (app()->runningInConsole()) {
return;
}

throw $e;
}
}

if (is_array($config['blueprint'])) {
Expand Down Expand Up @@ -74,7 +83,7 @@ public static function findResource(string $resourceHandle): ?Resource

public static function findResourceByModel(object $model): ?Resource
{
$resource = collect(static::$resources)->filter(fn (Resource $resource) => $resource->model()::class === $model::class)->first();
$resource = collect(static::$resources)->filter(fn (Resource $resource) => $model::class === $resource->model()::class)->first();

if (! $resource) {
throw new ResourceNotFound($model::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Statamic\Facades\Site;
use Statamic\Search\Result as ResultInstance;

class Searchable implements Contract, ContainsQueryableValues, Augmentable
class Searchable implements Augmentable, ContainsQueryableValues, Contract
{
use HasAugmentedInstance, ContainsSupplementalData;
use ContainsSupplementalData, HasAugmentedInstance;

protected $model;

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasRunwayResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

trait HasRunwayResource
{
use HasAugmentedInstance, FluentlyGetsAndSets;
use FluentlyGetsAndSets, HasAugmentedInstance;
use ResolvesValues {
resolveGqlValue as traitResolveGqlValue;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function authorFactory(int $count = 1, array $attributes = [])

class Post extends Model
{
use RunwayRoutes, HasRunwayResource;
use HasRunwayResource, RunwayRoutes;

protected $fillable = [
'title', 'slug', 'body', 'values', 'author_id', 'sort_order',
Expand Down

0 comments on commit 2f2c32a

Please sign in to comment.