♻️ Replace App\Model with App\Data
This commit is contained in:
parent
70e4404c22
commit
7f4f005302
12 changed files with 393 additions and 222 deletions
42
app/Data/InputData.php
Normal file
42
app/Data/InputData.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Exceptions\Quit;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
use Spatie\LaravelData\Attributes\WithCast;
|
||||
|
||||
class InputData extends Data
|
||||
{
|
||||
#[DataCollectionOf(FileData::class)]
|
||||
#[MapInputName('input')]
|
||||
public DataCollection $files;
|
||||
public ?string $url = null;
|
||||
#[WithCast(Casts\Folder::class)]
|
||||
public ?string $destination = null;
|
||||
public ?string $title = null;
|
||||
public bool $sync = false;
|
||||
|
||||
public function assertValid(): self
|
||||
{
|
||||
throw_if(
|
||||
!$this->hasFiles() && !$this->hasURL(),
|
||||
Quit::class,
|
||||
'Must have either a valid file or URL'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasURL(): bool
|
||||
{
|
||||
return !empty($this->url);
|
||||
}
|
||||
|
||||
public function hasFiles(): bool
|
||||
{
|
||||
return !empty($this->files) && !!$this->files->count();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue