lasthourcloud/app/Http/Livewire/Dev/S3Test.php

43 lines
936 B
PHP
Raw Normal View History

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;
use Livewire\WithFileUploads;
2023-08-07 13:31:42 +00:00
class S3Test extends Component
{
use WithFileUploads;
2023-08-07 13:31:42 +00:00
public $s3;
public $file;
public function mount()
{
2023-08-07 13:31:42 +00:00
$this->s3 = S3Storage::first();
}
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);
$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-07 13:31:42 +00:00
public function get_files()
{
set_s3_target($this->s3);
dd(Storage::disk('custom-s3')->files('files'));
}
}