so I am trying to make my label props as an optional. So If I don’t pass label props, its default value is false. I keep on getting the following error :
Unresolvable dependency resolving [Parameter #2 [ <required> $type ]] in class AppViewComponentsFormBaseFormInput
Here’s my code :
index.blade.php
<x-form.base-form-input :label="true" name="category" placeholder="Kategori" />
base-form-input.blade.php
@props([
'type' => 'text',
'placeholder' => '',
'label' => false,
])
<div class="form-group">
@if ($label)
<label for="name" class="text-primary fw-bold">{{ $name }}</label>
@endif
<input type="{{ $type }}" class="form-control" {{ $attributes->merge(['class']) }} id="{{ $name }}" aria-describedby="emailHelp" placeholder="{{ $placeholder }}" name="{{ $name }}">
</div>
BaseFormInput.php
class BaseFormInput extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $name;
public $placeholder;
public $type;
public $label;
public function __construct($name, $placeholder, $type, $label)
{
$this->name = $name;
$this->placeholder = $placeholder;
$this->type = $type;
$this->label = $label;
}
/**
* Get the view / contents that represent the component.
*
* @return IlluminateContractsViewView|Closure|string
*/
public function render()
{
return view('components.form.base-form-input');
}
}
I have tried doing <x-form-input :label="true"/>
but it still doesnt work. Please help
2
Answers
Did you try to pass default value to the construct ?
Laravel expects all four parameters
($name, $placeholder, $type, and $label)
to be provided when the BaseFormInput component is instantiated, but when you don’t provide them, Laravel throws this error.Change your
BaseFormInput
: