Scrap this, I was being an idiot and reading documentation is apparently hard
~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');
}
}
approved
value of null
, Blade will automatically cast that null
-value to false
.false // app/View/Components/RegistrationStatusComponent.php:17
This is how I am using the compnent btw;
php
$approved = $registration->approved;
dump($approved);
@endphp
<x-registration-status-component approved="$approved" />
#PHP #Laravel #Blade