0

I'm struggling with a soo stupid message, I don't see why I cannot call my Repository class

here is the controller using the class

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\FirebaseUserRepository;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {

        $firebaseUserRepository = new FirebaseUserRepository();
        $allUsers = $firebaseUserRepository->getAll();

        dd($allUsers);

        return view('home',$datas);
    }
}

here is controller calling the class

Here is the called class

<?php

namespace App\Repositories;

use App\Models\FirebaseUser;
use App\Services\FirebaseInstance as FirebaseInstance;

class FirebaseUserRepository implements \App\Repositories\RepositoryInterface
{

    protected $firebaseInstance;
    protected $firestoreInstance;
    public static $usersCollection = 'users';
    public $reference;

    /**
     * FirebaseUserRepository constructor.
     */
    public function __construct()
    {
        try {
            $this->firebaseInstance = new FirebaseInstance();
            $this->firestoreInstance = $this->firebaseInstance->getDatabase();
            $this->reference = $this->firebaseInstance->getReference(self::$usersCollection);
        }catch (\Exception $e)
        {
            die('firebase connection error : '.$e->getMessage());
        }

    }


    /**
     * @inheritDoc
     */
    public function create($arrayData): int
    {
        // TODO: Implement create() method.
    }

    /**
     * @inheritDoc
     */
    public function getAll(): array
    {
        $documents =  $this->reference->documents();
        $arrayUsers = array();
        foreach ($documents as $user) {
            if ($user->exists()){
                $newFirebaseUser = new FirebaseUser(
                    $user->createdAt(),
                    $user->email(),
                    $user->employeur(),
                    $user->gdprOkDate(),
                    $user->lastSeenAt(),
                    $user->name(),
                    $user->profileId(),
                    $user->token(),
                    $user->uid()
                );
                $arrayUsers[] = $newFirebaseUser;
            }
            return $arrayUsers;
        }
    }

    /**
     * @inheritDoc
     */
    public function get(int $id)
    {
        // TODO: Implement get() method.
    }

    /**
     * @inheritDoc
     */
    public function delete(int $id): bool
    {
        // TODO: Implement delete() method.
    }

    /**
     * @inheritDoc
     */
    public function update($id, $arrayData): bool
    {
        // TODO: Implement update() method.
    }
}

enter image description here

I've added the new folder Repositories to my composer.json

"autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories",
            "app/Models",
            "app/Repositories",
            "app/Services"
        ]
    },

tryed multiple times composer dump-autoload and php artisan config:cache, always the same result :

Symfony\Component\Debug\Exception\FatalThrowableError Class 'App\Repositories\FirebaseUserRepository' not found

Do you see what I've missed ?

Thanks for your help !

Eloise85
  • 648
  • 1
  • 6
  • 26
  • Your images of text [aren't very helpful](//meta.unix.stackexchange.com/q/4086). They can't be read aloud or copied into an editor, and they don't index very well, meaning that other users with the same problem are less likely to find the answer here. Please [edit] your post to incorporate the relevant text directly (preferably using copy+paste to avoid transcription errors). – Toby Speight Feb 05 '20 at 13:00
  • I've made that in order to see the filetree and terminal result, it's quicker to understand. – Eloise85 Feb 05 '20 at 13:05
  • You need to include your [mcve] *directly in the question*, even if you also provide a picture to give further information. (And yes, your program output should be directly in the question; you can't expect people to download images just for you). – Toby Speight Feb 05 '20 at 13:06

1 Answers1

1

OK, it seems that the word Repository is reserved I renamed it FirebaseUserRepo and it works...‍♂️

Eloise85
  • 648
  • 1
  • 6
  • 26
  • i had same problem so i created new one -> tested -> work fine then i delete every thing and created new one has the same name for first one then it works fine why i'dont know – Mohamd Almhde Mar 03 '22 at 08:33