Thanks to visit codestin.com
Credit goes to github.com

Skip to content

array_key_exists(): Argument #2 ($array) must be of type array, Illuminate\View\ComponentAttributeBag given #41851

Closed
@cod3rshotout

Description

@cod3rshotout

Laravel Version: 8.6.11
PHP Version: 8.1.4
Database Driver & Version: MySQL 8.0.27

I have created a component called Input and I'm calling it in the following way:

<x-input type="text" class="test" name="fullname" placeholder="hello" required></x-input>

The component use the following class:

<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Input extends Component
{
    public $name;
    public $type;
    public $prepend;
    public $prependText;
    public $append;
    public $appendText;

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($name)
    {
        $this->name = $this->dot_str($name);
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {
        return view('components.input');
    }

    private function dot_str($string)
    {
        return str_replace(['[', ']'], ['.', ''], $string);
    }
}

and this is the blade file:

{!! Form::{$type ?? 'text'}($name, old($name, $value ?? ''), $attributes->merge(['class' => $errors->first($name, ' is-invalid')])) !!}

as you can see I'm using laravelcollective/html and when I load the page I get:

array_key_exists(): Argument #2 ($array) must be of type array, Illuminate\View\ComponentAttributeBag given (View: /usr/src/app/resources/views/components/input.blade.php)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions