以https://github.com/codingyu/laravel-ueditor為例
--------------------------下面原文檔說明---------------------------------
上傳完成事件
Codingyu\LaravelUEditor\Events\Uploaded
它有兩個屬性:
$event->file 與 Uploading 一樣,上傳的文件
$event->result 上傳結(jié)構(gòu),數(shù)組,包含以下信息:
'state' => 'SUCCESS',
'url' => 'http://xxxxxx.qiniucdn.com/xxx/xxx.jpg',
'title' => '文件名.jpg',
'original' => '上傳時的源文件名.jpg',
'type' => 'jpg',
'size' => 17283,
你可以監(jiān)聽此事件用于一些后續(xù)處理任務(wù),比如記錄到數(shù)據(jù)庫。
--------------------------下面具體調(diào)用處理---------------------------------
打開App\Providers\EventServiceProvider.php,添加該事件處理
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'Codingyu\LaravelUEditor\Events\Uploaded'=>[
'App\Listeners\UploadedListener',
]
];
在App\Listeners\UploadedListener.php添加具體處理,下面為圖片添加水印處理
<?php
namespace App\Listeners;
use Codingyu\LaravelUEditor\Events\Uploaded;
use Log;
use Intervention\Image\ImageManagerStatic as Image;
class UploadedListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\OrderShipped $event
* @return void
*/
public function handle(Uploaded $event)
{
Log::info(json_encode($event));
$result=$event->result;
// Access the order using $event->order...
$imgPath = storage_path() .'/app/public/'. $result['title'];
//$spaceFilter=str_replace(" ", "\\ ",$imgPath);
//list($imgWidth, $imgHeight, $type, $attr) = getimagesize($imgPath);
$img = Image::make($imgPath);
$img->insert(storage_path() . '/app/watermark.png', 'bottom-right', 0, 0);
$img->save();
}
}
這樣完成事件調(diào)用使用