Skip to main content

Dcat Admin 富文本&MarkDown编辑器设置

富文本

表单

$form->editor('content')->imageDirectory(FunctionHelper::editorImgPath())->saving(function ($v) {
  return FunctionHelper::imgToCdn($v);
});

# 切换图片路径
public static function editorImgPath()
{
  return 'editor/' . config('admin.upload.directory.image') . '/' . date('Y/m/d');
}

详情

$show->content()->as(function ($content) {
  return "{$content}";
})->unescape();

Markdown

表单:

$form->markdown('doc')->imageDirectory(FunctionHelper::markdownImgPath())->saving(function ($v) {
	return FunctionHelper::imgToCdn($v);
});

# 自定义图片存储路径
public static function markdownImgPath()
{
  return 'markdown/' . config('admin.upload.directory.image') . '/' . date('Y/m/d');
}

# 图片等文件 cdn 域名替换
public static function imgToCdn($content)
{
  $content = str_replace('http://test.oss-cn-qingdao.aliyuncs.com', config('filesystems.img_cdn_url'), $content);
  $content = str_replace('https://test.oss-cn-qingdao.aliyuncs.com', config('filesystems.img_cdn_url'), $content);
  return $content;
}

详情:

use Dcat\Admin\Widgets\Markdown;
use Dcat\Admin\Widgets\Card;

$show->field('doc')->as(function ($doc) {
	return Card::make(
		Markdown::make($doc)
	);
})->unescape();