2

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.

2 Answers 2

3

When your data contains HTML tags then use

Write your code in blade file like

{!! $blog->body !!}
Sign up to request clarification or add additional context in comments.

1 Comment

Please mark as verified if its help for you Thank you for UPVOTING !!!...
0

Try this with php syntax like

{!! $blog->body !!}

Note: Make sure that your editor sending proper html content?

1 Comment

Why use @php when you can {!! $blog->body !!} . Try to avoid @php as much as you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.