Huh... this is interesting in Laravel. Say you have a model, let's call it Registration
and it has nullable boolean as one of its fields. Let call that field approved
where null
means "not yet decided", "false" is declined and "true" is accepted.
If you throw in that field into a custom Blade component like so;
class RegistrationStatusComponent extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
public null | bool $approved
) {
dd($this->approved);
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.registration-status-component');
}
}
If you throw in a model that has an
approved
value of null
, Blade will automatically cast that null
-value to false
.false // app/View/Components/RegistrationStatusComponent.php:17
I was today years old when I learned that this is apparently a thing.
#PHP #Laravel #Blade