How submitting this form trigger method of a component?

217 views Asked by At

In laravel 9 I have component which I created with command

php artisan make:component  ProductCardReport

In app/View/Components/ProductCardReport.php I get some data with eloquent :

<?php

namespace App\View\Components;

use App\Library\ReportProduct;
use Illuminate\View\Component;

class ProductCardReport extends Component
{
    public string $productId;
    public function __construct(string $productId)
    {
        $this->productId = $productId;
    }

    public function render()
    {
        $productData = getProductData($this->productId);
        ...
        return view('components.product-card-report', [
            'productId' => $this->productId,
            'productData'          => $productData,

        ]);
    }
}

and template of this component resources/views/components/product-card-report.blade.php which includes form for data submiting:

<x-slot name="header"> 
  Product Card
</x-slot>

 
    <form method="POST" action="{{ route('admin.generatePdfByContent') }}" accept-charset="UTF-8"
          id="form_print_to_pdf_content" name="form_print_to_pdf_content"
          enctype="multipart/form-data">
        {!! csrf_field() !!}

        <a @click.prevent="generateIntoFile()" class="editor_form_btn_save mr-4">
            {!! AppContent::showIcon(App\Enums\SvgIconType::GENERATE, App\Enums\SvgIconSize::MEDIUM) !!}
            Generate
            </a>
        <input type="__hidden" id="pdf_content" name="pdf_content"
               value=" pdf_content lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ">
    </form>

    <div id="div_card_report_content" class="w-full d">

By submitting this form acion of generatePdfByContent app/Http/Controllers/Admin/ProductController.php is triggered and in this method all job is done, but I dislike a lot that I have to call method generatePdfByContent of ProductController from component view file. But reading this https://laravel.com/docs/9.x/blade#rendering-components docs I do not see how can I by submitting form in view of component to call method of the component ?
Is it possible somehow?

Maybe some other desision is possible? What else can be triggered(which action) by form submitting?

Thanks!

0

There are 0 answers