SQLSTATE[22032]: <>: 3140 Invalid JSON text: “Invalid value.” at position 0 in value for column ‘products.product_active_matterials’

I got this error while inputing data through form in my laravel project that some column in database having json datatype.

ProductController.php

<?php

namespace AppHttpControllersManagement;

use AppCoreBaseResponse;
use AppHttpControllersController;
use AppServicesProductService;
use IlluminateHttpJsonResponse;
use IlluminateHttpRequest;
use AppModelsProduct;

class ProductController extends Controller
{

    protected $service;

    public function __construct(ProductService $service)
    {
        $this->service = $service;
    }

    public function index()
    {
        return view('backend.product.index');
    }

    public function table(): JsonResponse
    {
        $users = $this->service->getTable();

        return BaseResponse::json($users);
    }

    public function store(Request $request)
    {
        try {
            # get post parameters
            $post_parameters = $request->input();

            # create new equipment
            $this->service->store($post_parameters);

            # return response
            return BaseResponse::json([
                'success' => 1,
                'message' => "Success to create new product {$post_parameters['product_name']}"
            ]);
        }
        catch (Exception $e) {
            return BaseResponse::json([
                'success' => 0,
                'message' => $e->getMessage(),
                'data' => $post_parameters
            ]);
        }
    }
}

ProductService.php

<?php

namespace AppServices;

use AppLibrariesNanoId;
use AppModelsProduct;
use AppRepositoriesProductRepository;

class ProductService
{

    protected $repository;

    public function __construct()
    {
        // Add your constructor logic here
        $this->repository = new ProductRepository();
        
    }

    public function getTable()
    {
        $product = $this->repository->getTable();

        return $product;
    }

    public function store(array $data)
    {
        $checkProductName = $this->repository->getProductName($data);
        if (!empty($checkProductName))
            throw new Exception('Product Already Registered');

        # generate id
        $nano_id_library = new NanoId();
        $id = $nano_id_library->generateId(false);
        # prepare insert parameters
        $insertParameters = [
            'product_id' => $id,
            'product_code' => $data['product_code'],
            'product_name' => $data['product_name'],
            'product_active_matterials' => $data['product_active_matterials'],
            'product_group' => $data['product_group'],
            'product_pest_target' => $data['product_pest_target'],
            'product_dossage_min' => $data['product_dossage_min'],
            'product_dossage_max' => $data['product_dossage_max'],
            'product_uom' => $data['product_uom'],
            
        ];
        
        $opr = $this->repository->store($insertParameters);

        return $opr;
    }

    public function getById(string $id): object
    {
        return $this->repository->getById($id);
    }
}

product.js

$('#btn-save').on('click', function (e) {
    $('#btn-save')[0].setAttribute('data-kt-indicator', 'on');
    HELPER.block();

    // Disable button to avoid multiple click
    // $('#btn-save')[0].disabled = true;
    if (validator) {
        validator.validate().then(function (status) {

            if (status == 'Valid') {
                // Simulate form submission. For more info check the plugin's official documentation: https://sweetalert2.github.io/
                let data = $('#form-add-new-user').serializeArray();

                $.ajax({
                    url: BASEURL + "/management/product/" + ($('#product_id').val() ? "update" : "store"),
                    type: $('#product_id').val() ? "PUT" : "POST",
                    data: data,
                    dataType: "json",
                    success: function(response) {
                        if (response.success !== 1) {
                            errorAlert(response.message);
                        }
                        else {
                            successAlert(response.message);
                            $(`[data-bs-dismiss="modal"]`).trigger("click");
                            init();
                        }
                    },
                    error: function(xhr, status, error) {
                        errorAlert('Something went wrong!');
                    }
                });
            }
        });
    }

    HELPER.unblock()
});

Product.php(models)

<?php

namespace AppModels;

// use IlluminateContractsAuthMustVerifyEmail;

use AppTraitsDrawTable;
use AppTraitsLoggable;
use IlluminateDatabaseEloquentConcernsHasUuids;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentRelationsHasOne;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
use LaravelSanctumHasApiTokens;
use SpatieActivitylogLogOptions;
use SpatieActivitylogTraitsLogsActivity;
use SpatiePermissionTraitsHasRoles;
use IlluminateDatabaseEloquentSoftDeletes;

class Product extends Authenticatable
{

    use HasFactory, LogsActivity, HasUuids, Loggable, DrawTable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $table = 'products';

    protected $fillable = [
        'product_id',
        'product_code',
        'product_name',
        'product_active_matterials',
        'product_group',
        'product_pest_target',
        'product_dossage_min',
        'product_dossage_max',
        'product_uom',
    ];

    protected $casts = [
        'product_active_matterials' => 'array',
        'product_pest_target' => 'array',
    ];

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logOnly(['*'])
            ->dontSubmitEmptyLogs()
            ->useLogName('products');
    }
}

already looking for some resolve in eloquent laravel docs, but all the docs explain when we declared it inside the file, not with userinput.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật