58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php declare(strict_types=1);
 | 
						|
 | 
						|
namespace App\View\Components\Private\Forms;
 | 
						|
 | 
						|
use Illuminate\Support\Str;
 | 
						|
use Illuminate\View\View;
 | 
						|
 | 
						|
final class Checkbox extends Form
 | 
						|
{
 | 
						|
    public function __construct(
 | 
						|
        private readonly string $title,
 | 
						|
        private readonly string $name,
 | 
						|
        private readonly string $checkboxValue,
 | 
						|
        private readonly ?string $userValue = '',
 | 
						|
        private readonly ?string $notCheckedValue = null
 | 
						|
    ) { }
 | 
						|
 | 
						|
    protected function getName(): string
 | 
						|
    {
 | 
						|
        return $this->name;
 | 
						|
    }
 | 
						|
 | 
						|
    private function getTitle(): string
 | 
						|
    {
 | 
						|
        return Str::ucfirst($this->title);
 | 
						|
    }
 | 
						|
 | 
						|
    private function getCheckboxValue(): string
 | 
						|
    {
 | 
						|
        return (string) old($this->getRequestName(), $this->checkboxValue);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getUserValue(): string
 | 
						|
    {
 | 
						|
        return (string) $this->userValue;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getNotCheckedValue(): ?string
 | 
						|
    {
 | 
						|
        return $this->notCheckedValue;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @inheritDoc
 | 
						|
     */
 | 
						|
    public function render(): View
 | 
						|
    {
 | 
						|
        return view('private.components.forms.checkbox', [
 | 
						|
            'title' => $this->getTitle(),
 | 
						|
            'name' => $this->getName(),
 | 
						|
            'requestName' => $this->getRequestName(),
 | 
						|
            'checkboxValue' => $this->getCheckboxValue(),
 | 
						|
            'userValue' => $this->getUserValue(),
 | 
						|
            'notCheckedValue' => $this->getNotCheckedValue(),
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
}
 |