Laravel Filemanager具有可以使用EventServiceProvider
挂接的事件。我在下面列出了这些内容:
在一个例子中,他们有这个:
public function onImageWasUploaded(ImageWasUploaded $event)
{
$path = $event->path();
//your code, for example resizing and cropping
}
因此在这种情况下,您可以将路径保存到数据库。
我正在尝试以下操作:
<?php
namespace App\Listeners;
use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
use App\FileMetaData;
class HasUploadedListener
{
/**
* Handle the event.
*
* @param ImageWasUploaded $event
* @return void
*/
public function handle(ImageWasUploaded $event)
{
$name = '';
$department = '';
$category = '';
$type = '';
$size = '';
// Get te public path to the file and save it to the database
$filepath = $event->path();
FileMetaData::create(
[
'name' => '1',
'department' => '2',
'category' => 3,
'type' => 77,
'size' => 00,
'filepath' => $filepath
]
);
}
}
现在,我知道使用Storage()
可以得到我想要填写表格的所有数据,如下所示:
$fileList = Storage::allFiles('files/shares');
// Loop through the tag array that we just created
foreach ($fileList as $files) {
$file = FileMetaData::updateOrCreate(
[
'name' => basename($files),
'department' => basename(dirname($files)),
'category' => null,
'type' => Storage::mimeType($files),
'size' => Storage::size($files),
'filepath' => Storage::url($files)
]
);
}
在这种情况下,文件上传后是否可以使用存储来获取所需的数据?