Nobody has an idea?
Jan 20, 2025
8
Level 1
Optional parameters in component __construct
Hi guys
I have a Component that doesn't work fine.
class input extends Component
{
public $name;
public $value;
public $step;
public $required;
public function __construct($name, $value = null, $step = null, $required = null)
{
$this->name = $name;
$this->value = $value ?? '';
$this->step = $step ?? '';
$this->required = $required ?? 0;
}
<input name="{{$name}}" value="{!!old($name, $value)!!}" {{$step ? 'step='.$step : ''}} {{$required ? 'required' : ''}}
<x-be.input label="{{__('Name')}}" name="name" class="w-1/2" />
So, I have a component with many parameters that could be null, and I defined that in the construct. On the local machine (MacOS), it works, but on the server (Ubuntu), Laravel returns the error "Undefined variable $value."
Where I'm wrong?
Level 102
Probably not related, but linux is case sensitive (mac os is not normally). So there is a difference between Input and input. I notice your class is lowercase. Normally classes always start with a capital letter.
Please or to participate in this conversation.