<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public static function boot()
{
parent::boot();
static::deleted(function ($model)
{
//这样可以拿到当前操作id
//dd($model->id);
// content 字段内容
//dd($model->content);
$img = get_html_first_imgurl($model->content,true);
foreach ($img as $i){
$url = parse_url($i);
if(isset($url['path']) ){
$file = str_replace(array('/','\\'),DIRECTORY_SEPARATOR,public_path($url['path']));
//dump($file);
if(is_file($file)) unlink($file);
}
}
});
}
}