From 235ed6452b279212bcb2e693a164dff653272117 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 15 Oct 2025 11:04:05 +0300 Subject: [PATCH 1/2] fix: fixing fields that should be displayed on mcp index --- src/Fields/OrganicField.php | 22 ++++++++++++++++++---- tests/Fields/FieldMcpVisibilityTest.php | 5 +++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Fields/OrganicField.php b/src/Fields/OrganicField.php index 74701fab4..af697e550 100644 --- a/src/Fields/OrganicField.php +++ b/src/Fields/OrganicField.php @@ -3,7 +3,9 @@ namespace Binaryk\LaravelRestify\Fields; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; +use Binaryk\LaravelRestify\MCP\Requests\McpIndexRequest; use Binaryk\LaravelRestify\MCP\Requests\McpRequestable; +use Binaryk\LaravelRestify\MCP\Requests\McpShowRequest; use Binaryk\LaravelRestify\Traits\ProxiesCanSeeToGate; use Closure; use Illuminate\Http\Request; @@ -65,7 +67,7 @@ public function hideFromShow($callback = true) $this->showOnShow = is_callable($callback) ? function () use ($callback) { return ! call_user_func_array($callback, func_get_args()); } - : ! $callback; + : ! $callback; return $this; } @@ -75,21 +77,25 @@ public function hideFromIndex($callback = true) $this->showOnIndex = is_callable($callback) ? function () use ($callback) { return ! call_user_func_array($callback, func_get_args()); } - : ! $callback; + : ! $callback; return $this; } public function showOnMcp($callback = true) { - $this->showOnMcp = $callback; + $this->showOnMcp = $callback instanceof Closure + ? $callback + : fn() => (bool) $callback; return $this; } public function hideFromMcp($callback = true) { - $this->hideFromMcpCallback = $callback; + $this->hideFromMcpCallback = $callback instanceof Closure + ? $callback + : fn() => (bool) $callback; return $this; } @@ -154,6 +160,14 @@ public function isShownOnMcp(RestifyRequest $request, $repository): bool return call_user_func($this->showOnMcp, $request, $repository); } + if ($request instanceof McpShowRequest) { + return $this->isHiddenOnShow($request, $repository) === false; + } + + if ($request instanceof McpIndexRequest) { + return $this->isHiddenOnIndex($request, $repository) === false; + } + return $this->showOnMcp; } diff --git a/tests/Fields/FieldMcpVisibilityTest.php b/tests/Fields/FieldMcpVisibilityTest.php index afd2b9a13..13687cbc9 100644 --- a/tests/Fields/FieldMcpVisibilityTest.php +++ b/tests/Fields/FieldMcpVisibilityTest.php @@ -5,6 +5,7 @@ use Binaryk\LaravelRestify\Fields\Field; use Binaryk\LaravelRestify\Fields\FieldCollection; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; +use Binaryk\LaravelRestify\MCP\Requests\McpIndexRequest; use Binaryk\LaravelRestify\MCP\Requests\McpRequest; use Binaryk\LaravelRestify\Tests\Fixtures\Post\PostRepository; use Binaryk\LaravelRestify\Tests\IntegrationTestCase; @@ -30,7 +31,7 @@ public function test_field_collection_filters_mcp_hidden_fields_for_index(): voi }), // Conditional MCP visibility ]); - // Regular request +// // Regular request $regularRequest = new RestifyRequest; $regularIndexFields = $fields->forIndex($regularRequest, $this->repository); @@ -41,7 +42,7 @@ public function test_field_collection_filters_mcp_hidden_fields_for_index(): voi $this->assertContains('admin_notes', $regularFieldNames); // MCP request without admin - $mcpRequest = new McpRequest; + $mcpRequest = new McpIndexRequest(); $mcpIndexFields = $fields->forIndex($mcpRequest, $this->repository); $mcpFieldNames = $mcpIndexFields->map(fn ($field) => $field->getAttribute())->toArray(); From d942aac005f954b51002b3912423e91a923ac67f Mon Sep 17 00:00:00 2001 From: binaryk Date: Wed, 15 Oct 2025 08:04:40 +0000 Subject: [PATCH 2/2] Fix styling --- src/Fields/OrganicField.php | 8 ++++---- tests/Fields/FieldMcpVisibilityTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Fields/OrganicField.php b/src/Fields/OrganicField.php index af697e550..fbc518698 100644 --- a/src/Fields/OrganicField.php +++ b/src/Fields/OrganicField.php @@ -67,7 +67,7 @@ public function hideFromShow($callback = true) $this->showOnShow = is_callable($callback) ? function () use ($callback) { return ! call_user_func_array($callback, func_get_args()); } - : ! $callback; + : ! $callback; return $this; } @@ -77,7 +77,7 @@ public function hideFromIndex($callback = true) $this->showOnIndex = is_callable($callback) ? function () use ($callback) { return ! call_user_func_array($callback, func_get_args()); } - : ! $callback; + : ! $callback; return $this; } @@ -86,7 +86,7 @@ public function showOnMcp($callback = true) { $this->showOnMcp = $callback instanceof Closure ? $callback - : fn() => (bool) $callback; + : fn () => (bool) $callback; return $this; } @@ -95,7 +95,7 @@ public function hideFromMcp($callback = true) { $this->hideFromMcpCallback = $callback instanceof Closure ? $callback - : fn() => (bool) $callback; + : fn () => (bool) $callback; return $this; } diff --git a/tests/Fields/FieldMcpVisibilityTest.php b/tests/Fields/FieldMcpVisibilityTest.php index 13687cbc9..38bf5e765 100644 --- a/tests/Fields/FieldMcpVisibilityTest.php +++ b/tests/Fields/FieldMcpVisibilityTest.php @@ -31,7 +31,7 @@ public function test_field_collection_filters_mcp_hidden_fields_for_index(): voi }), // Conditional MCP visibility ]); -// // Regular request + // // Regular request $regularRequest = new RestifyRequest; $regularIndexFields = $fields->forIndex($regularRequest, $this->repository); @@ -42,7 +42,7 @@ public function test_field_collection_filters_mcp_hidden_fields_for_index(): voi $this->assertContains('admin_notes', $regularFieldNames); // MCP request without admin - $mcpRequest = new McpIndexRequest(); + $mcpRequest = new McpIndexRequest; $mcpIndexFields = $fields->forIndex($mcpRequest, $this->repository); $mcpFieldNames = $mcpIndexFields->map(fn ($field) => $field->getAttribute())->toArray();