2023-08-07 13:31:42 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
namespace App\Http\Livewire\Dev;
|
2023-08-07 13:31:42 +00:00
|
|
|
|
|
|
|
use App\Models\S3Storage;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Livewire\Component;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\WithFileUploads;
|
2023-08-07 13:31:42 +00:00
|
|
|
|
|
|
|
class S3Test extends Component
|
|
|
|
{
|
|
|
|
use WithFileUploads;
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 13:31:42 +00:00
|
|
|
public $s3;
|
|
|
|
public $file;
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-07 13:31:42 +00:00
|
|
|
$this->s3 = S3Storage::first();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function save()
|
|
|
|
{
|
2023-08-07 13:31:42 +00:00
|
|
|
try {
|
|
|
|
$this->validate([
|
|
|
|
'file' => 'required|max:150', // 1MB Max
|
|
|
|
]);
|
|
|
|
set_s3_target($this->s3);
|
2023-08-08 09:51:36 +00:00
|
|
|
$this->file->storeAs('files', $this->file->getClientOriginalName(), 'custom-s3');
|
2023-08-07 13:31:42 +00:00
|
|
|
$this->emit('success', 'File uploaded successfully.');
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
return general_error_handler($th, $this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 13:31:42 +00:00
|
|
|
public function get_files()
|
|
|
|
{
|
|
|
|
set_s3_target($this->s3);
|
|
|
|
dd(Storage::disk('custom-s3')->files('files'));
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|