mardi 7 avril 2020

in laravel error Invalid argument supplied for foreach() (View: i cant see $value

I am trying to make a blog foreach that see this erro Invalid argument supplied for foreach() (View:

my site https://weadam.com/

my code is: controller:

 public function index()
    {
        $localetmp = Session::get('locale');
        $blogs = @json_decode(file_get_contents("https://www.weadam.com/blogs/wp-json/wp/v2/posts?per_page=4&lang=" . $localetmp));
        $blogsold = Blog::orderBy('id','desc')->take(100)->get();

        foreach ((array)$blogs as $blog){
            // $blog->elapsed = $this->time_elapsed_string('@'.$blog->date);
            // $blog->date = date("d F Y",$blog->date);
        }
        $error = "";
        return view('home-new',['blogs' => $blogs]);
    }

and view is:

<div class="eng-home-blog">
                <div class="col-sm-9 home-post-disp bx-shadow brd-radius bg-white">
                    @foreach($blogs as $blog)
                        @if($blog->sticky)
                            <img src="" alt="" class="img-responsive brd-radius bx-shadow">
                            <div class="hm-post-date"></div>
                            <h3></h3>
                            <p>{!!$blog->excerpt->rendered!!}</p>
                            <span><a href="" target="_blank"></a></span>
                        @endif
                    @endforeach
                </div>
            </div>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire