Class not found in controller

Asked

Viewed 91 times

1

I am trying to make use of two classes in a controller (Franchiserepository and Orderrepository), but these classes are not being found in my controller. Below is the code of the classes and the stacktrace of error:

Error inserir a descrição da imagem aqui

Ordercontroller

namespace App\Controllers;

use \Symfony\Component\HttpFoundation\Request;
use \Symfony\Component\HttpFoundation\Response;
use \App\Services\JsonService as Json;
use \App\Repositories\FranchiseRepository as Franchise;
use \App\Repositories\OrderRepository as Order;

class OrderController
{
    protected $franchise;
    protected $order;

    public function __construct()
    {
        $this->franchise = new Franchise;
        $this->order = new Order;
    }

    public function sendOrders(Request $req, Response $res)
    {
        // select all active and enabled to send data to nappsolution franchises
        $franchises = $this->franchise->getNappFranchises();
        var_dump($franchises);
    }
} 

Franchiserepository

namespace App\Repositories;

use App\Models\Franchise;

class FranchiseRepository
{

    protected $franchise;

    public function __construct()
    {
        $this->franchise = new Franchise;
    }

    public function getNappFranchises()
    {
        return $this->franchise->select('napp_network_id', 'napp_user', 'napp_pass', 'napp_id')
                    ->where([
                        ['active', '=', true],
                        ['napp', '=', true]
                    ])
                    ->get();
    }
} 

Orderrepository

namespace \App\Repositories;

use App\Models\Order;

class OrderRepository
{

    protected $order;

    public function __construct()
    {
        $this->order = new Order;
    }
} 

  • In the code I saw no problem. Inside the server the class Franchiserepository is inside the specified namespace (App Repositories)? Please check the directory hierarchy.

  • The problem was that I had not loaded the App Repositories namespace in the psr-4 autoload of Poser haha

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.