Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

omarsow94's avatar

Repositories

I have Class App\Repositories\ConversationRepository does not exist error but in my controller i put : use App\Repositories\ConversationRepository; and in my Repositories\ConversationRepository i put namespace App\Repositories; . I think everythink is OK but this error message still

0 likes
30 replies
bestmomo's avatar

Looks weird, check the typo, sometimes there is a hidden stuff...

omarsow94's avatar

I change

use App\Repositories\ConversationRepository;

to

use App\Repositories\test;

so normally i should have this message error

Class App\Http\Controllers\test does not exist

but not i have the same message

Class App\Http\Controllers\ConversationRepository does not exist
impbob36's avatar

Some OSs are case sensitive too. Double check the filenames, and directories, have the same capitalized case.

Run the following to flush out data

composer dumpautoload
php artisan cache:clear
php artisan config:clear
omarsow94's avatar

I still have the same error after running the commands lines @impbob

Class App\Http\Controllers\ConversationRepository does not exist
omarsow94's avatar

the whole controller :

<?php

namespace App\Http\Controllers;

use App\Repositories\ConversationRepository;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Illuminate\Support\Facades\Auth;
use App\User;


class ConversationsController extends Controller
{
    private $r;
    private $auth;

    public function __construct(ConversationRepository $conversationRepository, AuthManager $auth)
    {
        $this->r = $conversationRepository;
        $this->auth = $auth;
    }
    public function index()
    {
        return view('conversations.index',[
            'users' => $this->r->getConversations($this->auth->user()->id)
        ]);
    }

    public function show(User $user)
    {
        return view('conversations.show',[
            'users' => $this->r->getConversations($this->auth->user()->id),
            'user' => $user
        ]);
    }

    public function store(User $user, Request $request)
    {
        $this->r-createMessage(
            $request->get('content'),
            $request->auth->user()->id,
            $user->id
        );
    }


}

@jbloomstrom

jbloomstrom's avatar

The error could be coming from a different file. Can you post the snippet from your laravel log that contains the full error message?

omarsow94's avatar

@jbloomstrom the latest message in laravel.log file is :

[2018-01-18 01:07:18] local.ERROR: Class App\Http\Controllers\ConversationRepository does not exist {"exception":"[object] (ReflectionException(code: 0): Class App\Http\Controllers\ConversationRepository does not exist at /var/www/html/VueJS/chat/vendor/laravel/framework/src/Illuminate/Container/Container.php:811)
[stacktrace]
MaverickChan's avatar

conversations or conversation?

are they 2 different controller or just a mis-spelling error?

omarsow94's avatar

conversation @MaverickChan , i have ConversationsController with 's' and ConversationRepository without 's'

jbloomstrom's avatar

@omarsow94 Are you still getting the error? Can you post the rest of the stack trace from the error message and your ConversationRespository file?

jcmargentina's avatar

les to some deep debug here ok ?

  1. execute the "file" command on both files ... show us the the result.

  2. Show us the code of App\Repositories\ConversationRepository

  3. The error says "App\Http\Controllers\ConversationRepository does not exist" .... so is trying to look for the ConversationRepository Class in App\Http\Controllers .... WOOPS ... lets change a little bit the ConversationsController file for:

<?php

namespace App\Http\Controllers;

use App\Repositories\ConversationRepository;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Illuminate\Support\Facades\Auth;
use App\User;


class ConversationsController extends Controller
{
    private $r;
    private $auth;

    /* Look here */
    public function __construct(\\App\Repositories\ConversationRepository $conversationRepository, AuthManager $auth)
    {
        $this->r = $conversationRepository;
        $this->auth = $auth;
    }
    public function index()
    {
        return view('conversations.index',[
            'users' => $this->r->getConversations($this->auth->user()->id)
        ]);
    }

    public function show(User $user)
    {
        return view('conversations.show',[
            'users' => $this->r->getConversations($this->auth->user()->id),
            'user' => $user
        ]);
    }

    public function store(User $user, Request $request)
    {
        $this->r-createMessage(
            $request->get('content'),
            $request->auth->user()->id,
            $user->id
        );
    }


}

tell me how you go

omarsow94's avatar

I still have error, @jcmargentina when i replace my contruct param with ```(\App\Repositories\ConversationRepository $conversationRepository, AuthManager $auth) i have this error :

Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING)

@jbloomstrom my App\Repositories\ConversationRepository file

<?php

namespace App\Repositories;

use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Message;
use Carbon\Carbon;

class ConversationRepository
{

      private $user;
      private $message;

      public function __construct(User $user, Message $message)
      {
          $this->user = $user;
          $this->message = $message;
      }

      public function getConversations(int $userId) {
          $this->user->newQuery()
            ->select('name', 'id')
            ->where('id','!=', $userId)
            ->get();
      }

      public function createMessage(string $content, int $from, int $to){
          $this->message->newQuery()->create([
              'content' => $content;
              'from_id' => $from,
              'to_id' => $to,
              'created_at' => Carbon::now();
          ]);
      }

}

deepu07's avatar

If possible can you try App\Repositories\ConversationRepository as cRepository (like this give a try if it works for you)

deepu07's avatar
<?php

namespace App\Http\Controllers;

use App\Repositories\ConversationRepository as cRepository;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Illuminate\Support\Facades\Auth;
use App\User;

and replace all ConversationRepository into cRepository your code...try like this

omarsow94's avatar

Same error @deepu07 , i don't understand why Class App\Http\... doesn't exist , Http ? it's a Repository

deepu07's avatar

Is this Model ???

<?php

namespace App\Repositories;

use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Message;
use Carbon\Carbon;

class ConversationRepository
{

      private $user;
      private $message;

      public function __construct(User $user, Message $message)
      {
          $this->user = $user;
          $this->message = $message;
      }

      public function getConversations(int $userId) {
          $this->user->newQuery()
            ->select('name', 'id')
            ->where('id','!=', $userId)
            ->get();
      }

      public function createMessage(string $content, int $from, int $to){
          $this->message->newQuery()->create([
              'content' => $content;
              'from_id' => $from,
              'to_id' => $to,
              'created_at' => Carbon::now();
          ]);
      }

}

deepu07's avatar

If possible can you use tinker and find the result with id....by doing we will trace issue

App\Repositories\ConversationRepository::find(1) try this one in tinker

MaverickChan's avatar

@omarsow94 did you copy your files elsewhere or just created them locally? And Linux is case sensitive , the file name should be very accurate.

omarsow94's avatar

@deepu07 result :

>>> App\Repositories\ConversationRepository::getConversations(1);
PHP Deprecated:  Non-static method App\Repositories\ConversationRepository::getConversations() should not be called statically on line 1
omarsow94's avatar

It going ! I replace ConversationRepository by ConversationsRepository ( add s to Conversation) . Now i have this error : Trying to get property of non-object ( r ) on

  public function index()
    {
        return view('conversations.index',[
            'users' => $this->r->getConversations($this->auth->user()->id)
        ]);
    }

from my controller

<?php

namespace App\Http\Controllers;

use App\Repositories\ConversationsRepository;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Illuminate\Support\Facades\Auth;
use App\User;


class ConversationsController extends Controller
{
    private $r;
    private $auth;

    public function __construct(ConversationsRepository $conversationRepository, AuthManager $auth)
    {
        $this->r = $conversationRepository;
        $this->auth = $auth;
    }
    public function index()
    {
        return view('conversations.index',[
            'users' => $this->r->getConversations($this->auth->user()->id)
        ]);
    }

    public function show(User $user)
    {
        return view('conversations.show',[
            'users' => $this->r->getConversations($this->auth->user()->id),
            'user' => $user
        ]);
    }

    public function store(User $user, Request $request)
    {
        $this->r-createMessage(
            $request->get('content'),
            $request->auth->user()->id,
            $user->id
        );
    }


}

omarsow94's avatar
omarsow94
OP
Best Answer
Level 1

I work fine now , i don't know exactly why, i just replace ConversationRepository by ConversationsRepository ( add s to Conversation) .

1 like

Please or to participate in this conversation.