lasthourcloud/app/Livewire/Team/Storage/Form.php

62 lines
1.7 KiB
PHP
Raw Normal View History

2023-08-07 13:31:42 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Team\Storage;
2023-08-07 13:31:42 +00:00
use App\Models\S3Storage;
use Livewire\Component;
2023-08-07 13:31:42 +00:00
class Form extends Component
{
public S3Storage $storage;
protected $rules = [
2023-10-10 11:10:43 +00:00
'storage.is_usable' => 'nullable|boolean',
2023-08-07 13:31:42 +00:00
'storage.name' => 'nullable|min:3|max:255',
'storage.description' => 'nullable|min:3|max:255',
'storage.region' => 'required|max:255',
'storage.key' => 'required|max:255',
'storage.secret' => 'required|max:255',
'storage.bucket' => 'required|max:255',
'storage.endpoint' => 'required|url|max:255',
];
protected $validationAttributes = [
2023-10-10 11:10:43 +00:00
'storage.is_usable' => 'Is Usable',
2023-08-07 13:31:42 +00:00
'storage.name' => 'Name',
'storage.description' => 'Description',
'storage.region' => 'Region',
'storage.key' => 'Key',
'storage.secret' => "Secret",
'storage.bucket' => 'Bucket',
'storage.endpoint' => 'Endpoint',
];
public function test_s3_connection()
{
2023-08-07 13:31:42 +00:00
try {
$this->storage->testConnection(shouldSave: true);
2023-12-07 18:06:32 +00:00
return $this->dispatch('success', 'Connection is working. Tested with "ListObjectsV2" action.');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-07 13:31:42 +00:00
}
}
public function delete()
{
2023-08-07 13:31:42 +00:00
try {
$this->storage->delete();
return redirect()->route('team.storages.all');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-07 13:31:42 +00:00
}
}
2023-08-07 13:31:42 +00:00
public function submit()
{
$this->validate();
try {
$this->test_s3_connection();
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-07 13:31:42 +00:00
}
}
}