1. Go to this page and download the library: Download zeroar/withfile library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zeroar / withfile example snippets
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use Withfile\WithFile; // add this to implement
class UploadPhoto extends Component
{
use WithFile; // add this to implement
// this is target variable
// this variable will turn to array after upload file
public $photo;
// please implement this variable and add the variable target
// if you not implement this, WithFile will not working
public $fileable = [
'photo'
];
public function render() {
return view('livewire.upload-photo');
}
// implement this method to edit or save the file
public function updatedPhoto($value, $old_value)
{
// in this area, you can implement what you want for the file.
// to save the file, i recommend to try this for save file in local
$filename = $value['name'];
// below for customize filename
// $filename = "custom-file-name" . $value['extension'];
Storage::disk('public')->put($filename, $this->raw($value));
$this->photo = Storage::url($filename); // get the file url for saving to your database
}
}