Try a composer dumpautoload
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
Already done, but the message error still @bestmomo
Looks weird, check the typo, sometimes there is a hidden stuff...
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
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
I still have the same error after running the commands lines @impbob
Class App\Http\Controllers\ConversationRepository does not exist
Can you post the whole controller file?
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
);
}
}
The error could be coming from a different file. Can you post the snippet from your laravel log that contains the full error message?
@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]
conversations or conversation?
are they 2 different controller or just a mis-spelling error?
conversation @MaverickChan , i have ConversationsController with 's' and ConversationRepository without 's'
@omarsow94 if you are using linux or mac , check file ownership when you copy it from elsewhere.
I use Linux , i should put 777 ? (chmod) @MaverickChan
@omarsow94 try writing a new file , copy the content from the old .
@omarsow94 Are you still getting the error? Can you post the rest of the stack trace from the error message and your ConversationRespository file?
les to some deep debug here ok ?
-
execute the "file" command on both files ... show us the the result.
-
Show us the code of App\Repositories\ConversationRepository
-
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
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();
]);
}
}
If possible can you try App\Repositories\ConversationRepository as cRepository (like this give a try if it works for you)
same error @deepu07 :
Class App\Repositories\cRepository does not exist
<?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
Same error @deepu07 , i don't understand why Class App\Http\... doesn't exist , Http ? it's a Repository
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();
]);
}
}
No the repository . In Repositories folder @deepu07
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
@omarsow94 did you copy your files elsewhere or just created them locally? And Linux is case sensitive , the file name should be very accurate.
@MaverickChan i create a file locally , Ok @deepu07 i try stay touch
@deepu07 result :
>>> App\Repositories\ConversationRepository::getConversations(1);
PHP Deprecated: Non-static method App\Repositories\ConversationRepository::getConversations() should not be called statically on line 1
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
);
}
}
I work fine now , i don't know exactly why, i just replace ConversationRepository by ConversationsRepository ( add s to Conversation) .
Please or to participate in this conversation.