5 months ago

"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.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FetchPostsFromBlog extends Controller
    public static function postsfromjsonurl() {

        $jsonUrl = env('WP_URL');
        $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


    $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);


@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 class="card-body p-0">             
                <ul class="list-unstyled px-3">
                    @foreach ($news as $Snews)
                            $dataPub = $Snews['data']; 
                            $dataConv = date("d-m-Y", strtotime($dataPub));
                            $title = $Snews['title'];
                            $permalink = $Snews['link'];
                            $slug = $Snews['slug'];
                            $content = $Snews['content'];
                            <li class="border-bottom">
                                    data-titolo="{{ $title }}"
                                    data-content="{{ $content }}"
                                    data-dataPub="{!! $dataConv !!}"
                                    title="{{ $titolo }}"
                                    <span class="small text-muted"><strong>{!! $dataConv !!}</strong></span><br/><span class="font-italic">{!! $titolo !!}</span>

... Continue with others if

Thanks for any help!

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