Sander van Kasteel<p>Scrap this, I was being an idiot and reading documentation is apparently hard 😂 🤦♂️<span><br><br></span><del>~Huh... this is interesting in Laravel. Say you have a model, let's call it <code>Registration</code> and it has nullable boolean as one of its fields. Let call that field <code>approved</code> where <code>null</code> means "not yet decided", "false" is declined and "true" is accepted.</del><span>~<br><br></span><del>~If you throw in that field into a custom Blade component like so;</del><span>~<br></span></p><pre><code>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');
}
}</code></pre><span><br></span><del>~If you throw in a model that has an <code>approved</code> value of <code>null</code>, Blade will automatically cast that <code>null</code>-value to <code>false</code>.</del><span>~<br></span><pre><code>false // app/View/Components/RegistrationStatusComponent.php:17</code></pre><span><br>This is how I am using the compnent btw;</span><pre><code>php
$approved = $registration->approved;
dump($approved);
@endphp
<x-registration-status-component approved="$approved" /></code></pre><span><br></span><del>~I was today years old when I learned that this is apparently a thing.</del><span>~<br><br></span><a href="https://social.sandervankasteel.nl/tags/PHP" rel="nofollow noopener noreferrer" target="_blank">#PHP</a> <a href="https://social.sandervankasteel.nl/tags/Laravel" rel="nofollow noopener noreferrer" target="_blank">#Laravel</a> <a href="https://social.sandervankasteel.nl/tags/Blade" rel="nofollow noopener noreferrer" target="_blank">#Blade</a><p></p>