domegang
5 months ago
139
7
Laravel

"Class 'App\Http\Controllers\FetchPostsfromBlog' not found"

Posted 5 months ago by domegang

Hi guys, hi have a controller to fetch data from a json url. In my local machine it works great, i didnt get any problems. But i get the error "Class 'App\Http\Controllers\FetchPostsfromBlog' not found" on my server. Following some tutorial, i deployed laravel on a shared hosting.

Here's my controller.


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FetchPostsFromBlog extends Controller
{
    public static function postsfromjsonurl() {

        $jsonUrl = env('WP_URL');
        $arrContextOptions=array(
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ),
        );          
        $postsUrl = $jsonUrl.'/wp-json/data/posts';
        $data = file_get_contents($postsUrl, false, stream_context_create($arrContextOptions)); // put the contents of the file into a variable
        $posts = json_decode($data, true); // decode the JSON feed

        return $posts;
    }
}

and here my template where i show the data.


@php use App\Http\Controllers\FetchPostsfromBlog; @endphp

@php $posts = FetchPostsfromBlog::postsfromjsonurl(); @endphp

@php

    $news = array_filter($posts, function ($v) {
        return in_array('news', $v);
    });

    $comunicati = array_filter($posts, function ($v) {
        return in_array('com', $v);
    });

    $circolari = array_filter($posts, function ($v) {
        return in_array('circ', $v);
    });

@endphp

@if ($news)
    <div class="col-lg-4">
        <div class="card mb-3">
            <div class="card-header bg-success text-white">
                <h2 class="h6 font-weight-bold m-0">Last News</h2>
            </div>
            <div class="card-body p-0">             
                <ul class="list-unstyled px-3">
                    @foreach ($news as $Snews)
                        @php 
                            $dataPub = $Snews['data']; 
                            $dataConv = date("d-m-Y", strtotime($dataPub));
                            $title = $Snews['title'];
                            $permalink = $Snews['link'];
                            $slug = $Snews['slug'];
                            $content = $Snews['content'];
                        @endphp
                            <li class="border-bottom">
                                <article 
                                    id="contenutoPost"
                                    data-titolo="{{ $title }}"
                                    data-content="{{ $content }}"
                                    data-dataPub="{!! $dataConv !!}"
                                    title="{{ $titolo }}"
                                    data-toggle="modal" 
                                    data-target="#showPost"
                                >
                                    <span class="small text-muted"><strong>{!! $dataConv !!}</strong></span><br/><span class="font-italic">{!! $titolo !!}</span>
                                </article>
                            </li>
                    @endforeach
                </ul>
            </div>
        </div>
    </div>
@endif

... Continue with others if

Thanks for any help!

Please sign in or create an account to participate in this conversation.