With good luck to all, I show my Code in Laravel 9, with Tinymce to collect the data from the user through POST. I am working on laragon 6.
HTML
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"><script src="https://cdn.tiny.cloud/1/nftneibcgkgxik91ybc1kpaau1jmp6ljbpifsv1cnssjgq9h/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
@include('tiny')
tiny.blade.php added to html via @include
<script>
tinymce.init({
selector: "textarea", // Replace this CSS selector to match the placeholder element for TinyMCE
height: 400,
plugins: 'code table lists emoticons image media link',
toolbar1: 'undo redo | formatselect| bold italic | alignleft aligncenter alignright | indent outdent | bullist numlist | code | table emoticons',
toolbar2: 'image media | link unlink',
image_advtab: true ,
remove_linebreaks : false
});
</script>
View New Article
@extends('layout.layoutadmin')
@section('titulo','Nuevo Articulo')
@section('contenido')
<form action="narticulo" method="POST">
@csrf
<div class="row">
...
<div class="mt-2">
<textarea name="contenido">{{ old('contenido') }}</textarea>
@error('contenido')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
Through that Form I collect all the information to enter the database and with the controller I record it in mysql.
Controller AdminController
<?php
namespace App\Http\Controllers;
use App\Models\Blog;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class AdministracionController extends Controller{
public function graboarticulo(Request $request)
{
$request->validate([
'contenido' => ['required']
]);
$blog = new Blog;
$blog->contenido = $request->input('contenido');
$blog->save();
return to_route('articulos');
}
The problem is when I collect the data and show it on the screen, the full text that is entered from tinymce appears.
Function that collects the data from the base
public function veopost($slug){
$post = Blog::where('slug',$slug)->get();
return view('front.veo', ['post'=> $post]);
}
The view I show with
<div>{{ $post[0]->contenido}}</div>
And the following appears (Extract)
<p style="margin: 0px 0px 15px; padding: 0px; text-align: justify; font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; background-color: #ffffff;">á é í ó ú</p> <p style="margin: 0px 0px 15px; padding: 0px; text-align: justify; font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; background-color: #ffffff;">Al contrario del pensamiento popular, el texto de Lorem Ipsum no es simplemente texto aleatorio.
Have you tried using the blade syntax to not 'escape' the strings?
Instead of
{{ $post[0]->contenido }}
could you use
{!! $post[0]->contenido !!}
Laravel docs (english)