Reputation: 51
I am working on blog section of a project. I integrated ckeditor and saved data to database. When i display it in php it shows plain text instead of html. I have tried different ways but couldn't resolve the problem. Please some one guide me. thanks. my function to save data in database
public function store_blog(Request $request){
$fname=null;
if($request->hasFile('image')){
$file=$request->file('image');
$fileName=uniqid().'.'.$file->getClientOriginalExtension();
$file->move(public_path('uploads/blogs/'),$fileName);
$fname=asset('uploads/blogs/'.$fileName);
}
$bbody=$request->blog_body;
$bbody = trim($bbody);
$bbody = stripslashes($bbody);
$bbody = htmlspecialchars($bbody);
Blog::create([
"title"=>$request->title,
"short_description"=>$request->short_desp,
"body"=>$bbody,
"cover_image"=>$fname,
"slug"=>str_replace(" ","_",$request->title),
]);
return redirect()->route('blog_index')->with('success','Blog created successfully');
}
this function saves content successfully. But when i fetch and display in laravel blade view. Ckeditor content displayed all html as plain text/string. How can i force this to render html.
function to fetch blog from database
public function show_Ablog(Request $request,$slug){
$blog=Blog::where('slug',$slug)->first();
return view('website.showAblog',compact('blog'));
}
in my blade view
<div class="col-lg-12 dat">
{{($blog->body)}}
</div>
i have tried all functions like
htmlspecialchars
htmlentities
how could i resolve this.
Upvotes: 2
Views: 1583
Reputation: 36
Try this with php syntax like
{!! $blog->body !!}
Note: Make sure that your editor sending proper html content?
Upvotes: 0
Reputation: 6005
When your data contains HTML tags then use
Write your code in blade file like
{!! $blog->body !!}
Upvotes: 3