lasthourcloud/app/Http/Livewire/Project/Shared/Storages/All.php

36 lines
970 B
PHP
Raw Normal View History

2023-05-05 10:08:38 +00:00
<?php
2023-08-07 20:14:21 +00:00
namespace App\Http\Livewire\Project\Shared\Storages;
2023-05-05 10:08:38 +00:00
2023-05-05 12:20:10 +00:00
use App\Models\LocalPersistentVolume;
2023-05-05 10:08:38 +00:00
use Livewire\Component;
class All extends Component
{
2023-08-07 20:14:21 +00:00
public $resource;
2023-05-05 12:20:10 +00:00
protected $listeners = ['refreshStorages', 'submit'];
2023-05-05 10:08:38 +00:00
public function refreshStorages()
{
2023-08-07 20:14:21 +00:00
$this->resource->refresh();
2023-05-05 10:08:38 +00:00
}
2023-05-05 12:20:10 +00:00
public function submit($data)
{
try {
LocalPersistentVolume::create([
'name' => $data['name'],
'mount_path' => $data['mount_path'],
'host_path' => $data['host_path'],
2023-08-07 20:14:21 +00:00
'resource_id' => $this->resource->id,
'resource_type' => $this->resource->getMorphClass(),
2023-05-05 12:20:10 +00:00
]);
2023-08-07 20:14:21 +00:00
$this->resource->refresh();
2023-06-22 08:04:39 +00:00
$this->emit('success', 'Storage added successfully');
2023-05-05 12:20:10 +00:00
$this->emit('clearAddStorage');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
2023-06-09 13:55:21 +00:00
return general_error_handler(err: $e, that: $this);
2023-05-05 12:20:10 +00:00
}
}
2023-05-05 10:08:38 +00:00
}