From b1cc9f0ed05dd250563b5590a9aa6f4a54b57d0b Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Wed, 1 Oct 2025 09:48:09 +0300 Subject: [PATCH] Added `method` attribute for `Submit` component (#14) --- resources/views/submit.blade.php | 3 +++ src/CagiloServiceProvider.php | 7 +++++-- src/Components/Submit.php | 13 +++++++++++-- tests/Components/SubmitTest.php | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/resources/views/submit.blade.php b/resources/views/submit.blade.php index f8422f5..9c0ba15 100644 --- a/resources/views/submit.blade.php +++ b/resources/views/submit.blade.php @@ -1,4 +1,7 @@
+ @if($method) + @method($method) + @endif @csrf
diff --git a/src/CagiloServiceProvider.php b/src/CagiloServiceProvider.php index 20c2eac..c098ede 100644 --- a/src/CagiloServiceProvider.php +++ b/src/CagiloServiceProvider.php @@ -25,8 +25,11 @@ public function boot(IconFinder $iconFinder): void $this->loadViewsFrom(__DIR__.'/../resources/views', 'cagilo'); - collect(config('cagilo.components', []))->each(fn ($class, $alias) => Blade::component($alias, $class)); - collect(config('cagilo.icons', []))->each(fn ($path, $key) => $iconFinder->registerIconDirectory($key, $path)); + collect(config('cagilo.components', [])) + ->each(fn ($class, $alias) => Blade::component($alias, $class)); + + collect(config('cagilo.icons', [])) + ->each(fn ($path, $key) => $iconFinder->registerIconDirectory($key, $path)); } public function register(): void diff --git a/src/Components/Submit.php b/src/Components/Submit.php index fdcf2fa..0465474 100644 --- a/src/Components/Submit.php +++ b/src/Components/Submit.php @@ -26,14 +26,23 @@ class Submit extends Component */ public string $formId; + /** + * The HTTP method used when submitting the form. + * + * @var string|null + */ + public ?string $method; + /** * @param string $action + * @param string $method * @param string|null $formId */ - public function __construct(string $action, ?string $formId = null) + public function __construct(string $action, ?string $method = null, ?string $formId = null) { $this->action = Route::has($action) ? route($action) : $action; - $this->formId = $formId ?? (string) Str::uuid(); + $this->formId = $formId ?? Str::uuid()->toString(); + $this->method = $method; } /** diff --git a/tests/Components/SubmitTest.php b/tests/Components/SubmitTest.php index 383f845..1ef99d0 100644 --- a/tests/Components/SubmitTest.php +++ b/tests/Components/SubmitTest.php @@ -57,4 +57,12 @@ public function testRenderWithRouteNameComponent(): void ->blade('') ->assertSee('
blade('') + ->assertSee('assertSee('', false); + } }