cwsdigital / twill-metadata

SEO Metadata Package for Twill CMS
MIT License
30 stars 8 forks source link

Default medias Param is being conflicted for inserting the data #30

Closed abidkhan484 closed 2 days ago

abidkhan484 commented 4 days ago

Root Cause: The issue is caused by the initializeHasMetadata method, particularly in the HasMetadata.php section. When the mediasParams are being added, it interferes with the process of adding only the title field, which leads to an error when additional information is missing.

Error Details: The error is triggered when the framework attempts to run a database query, and it expects an array, but a string is provided instead. This happens in the Illuminate/Query/Grammers/Grammer.php file of the Laravel framework.

{
    "message": "Illuminate\\Database\\Grammar::parameterize(): Argument #1 ($values) must be of type array, string given, called in /zero/projects/fusion/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 1181",
    "exception": "TypeError",
    "file": "/zero/projects/fusion/vendor/laravel/framework/src/Illuminate/Database/Grammar.php",
    "line": 197,
    "trace": [
        {
            "file": "/zero/projects/fusion/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php",
            "line": 1181,
            "function": "parameterize",
            "class": "Illuminate\\Database\\Grammar",
            "type": "->"
        },
        {
            "function": "Illuminate\\Database\\Query\\Grammars\\{closure}",
            "class": "Illuminate\\Database\\Query\\Grammars\\Grammar",
            "type": "->"
        },
        {
            "file": "/zero/projects/fusion/vendor/laravel/framework/src/Illuminate/Collections/Arr.php",
            "line": 605,
            "function": "array_map"
        },
pauldwight commented 4 days ago

This is usually because your model doesn't have any defined mediaParams?

If it doesn't then define some mediaParams for the model.

public $mediasParams = [
        'cover' => [
            'default' => [
                [
                    'name' => 'default',
                    'ratio' => 16 / 9,
                ],
            ],
        ],
    ];
abidkhan484 commented 2 days ago

This is usually because your model doesn't have any defined mediaParams?

If it doesn't then define some mediaParams for the model.

public $mediasParams = [
        'cover' => [
            'default' => [
                [
                    'name' => 'default',
                    'ratio' => 16 / 9,
                ],
            ],
        ],
    ];

Hi @pauldwight, It's working after adding the attribute in the model. I have 2 observations.

  1. I have set the same in the metadata config with cover key, but it still didn't work. So, do I need to add the same attribute in all the models?
  2. It would be better to add this in the readme.

Thanks for the prompt support.