PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] problems displaying post details in laravel

 February 28, 2022     laravel     No comments   

Issue

I have the following problem related to displaying the details (title, content) of the blog posts.

I would like only the information in the post I accessed to appear.

in controller i have:

public function site($posts)
    {
        

        $theme = get_option('active_theme','default');
       

        if( file_exists( resource_path() . "/views/theme/$theme/postare/$posts.blade.php") ){    
            return view("theme.$theme.template.$posts");
            
        }else{
            abort(404);
        }

        // $post = Posts::where('posts_id', $posts->id)->get();
    }

In blade i have:

@foreach(\App\Posts::all()  as $posts)
                        <div class="col-md col-lg ml-auto mr-auto">
                            <h4 class="text-primary">Sub title</h4>
                            <h2 class=""><strong>{{ get_array_data($posts->title) }}</strong></h2>
                            <svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 0 40 20" width="40" class="mb-30 svg-primary" src="images/gallery/decor/line-h-1.svg" alt="sep"><path d="m0 8h40v4h-40z" fill-rule="evenodd"></path></svg>
                            <p class="">{!! get_array_data($posts->content) !!}</p>
                            
                        </div>
                    @endforeach

Solution

Thank you for your help. I solved it like this: in controller: public function show(Posts $posts, $id)//show only selected post

  {
    $posts = Posts::find($id);
    return view('theme.default.template.post_detalii', compact(['posts']));

        
  }

in blade:

<div class="col-md col-lg ml-auto mr-auto">
                            <h4 class="text-primary">Sub title</h4>
                            <div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
                            <h2  itemprop="name" class=""><strong>{!!( get_array_data($posts->title) )!!}</strong></h2>
                            <svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 0 40 20" width="40" class="mb-30 svg-primary" src="images/gallery/decor/line-h-1.svg" alt="sep"><path d="m0 8h40v4h-40z" fill-rule="evenodd"></path></svg>
                            <div itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
                            <p itemprop="text" class="">{!!( get_array_data($posts->content) )!!}</p>
                            
                        </div>


Answered By - Marian Giuglea
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing