public function store(Request $request)
{
$id = $request->blogpost_id;
$v = $request->validate([
'blogpost_title' => 'required',
'blogpost_slug' => 'required',
'blogpost_content' => 'required',
]);
/* $content = $request->blogpost_content;
libxml_use_internal_errors(true);
$dom = new \DomDocument();
$dom->loadHtml( mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$image_file = $dom->getElementsByTagName('img');
foreach($image_file as $key => $image) {
$file_name = pathinfo($image->getAttribute('data-filename'), PATHINFO_FILENAME);
$file_extention = pathinfo($image->getAttribute('data-filename'), PATHINFO_EXTENSION);
$file_fullname = $file_name . '-' . time() . '.' . $file_extention;
$data = $image->getAttribute('src');
if(substr($image->getattribute('src'),0,4) == 'data') {
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$img_data = base64_decode($data);
$image_name = "/uploads/blogs/" . $file_fullname;
$path = public_path() . $image_name;
file_put_contents($path, $img_data);
$image->removeAttribute('src');
$image->setAttribute('src', $image_name);
}
}
$content = $dom->saveHTML(); */
try {
DB::table('tbl_blogs_posts')->updateOrInsert(
[ 'id' => $id],
[
'category_id' => $request->blogpost_category,
'blogpost_title' => $request->blogpost_title,
'blogpost_slug' => $request->blogpost_slug,
'blogpost_thumbnail' => $request->blogpost_thumbnail,
'blogpost_content' => $request->blogpost_content,
'blogpost_author' => auth()->user()->name,
]
);
$notification = array(
'message' => 'Bài viết đã được cập nhật thành công',
'alert-type' => 'success'
);
} catch (\Throwable $th) {
$notification = array(
'message' => $th->getMessage(),
'alert-type' => 'error'
);
}
//return view('blogs.post_create');
return redirect('blogs/posts')->with($notification);
}
<div class="form-group">
<label class="col-form-label">Content</label>
<div class="">
<textarea name="blogpost_content" id="summary-ckeditor" class="form-control">{{ $blogpost_edit->blogpost_content }}</textarea>
@error('blogpost_content')
<p class="error text-danger">{{ $message }}</p>
@enderror
</div>
</div>