2

Using Laravel 5.4, I am getting this error on view whenever I call my method it shows on screen

(1/1) FatalThrowableError
Class 'App\Models\Chat\User' not found

Hierarchy of my project :

Controllers
    - ChatMessageController
Models
   -Chat
        -message.php
   -User.php

and here's my controller class code :

namespace App\Http\Controllers\Chat;

use App\Http\Controllers\Controller;
use App\Models\Chat\Message;
use App\Models\User;
use Illuminate\Http\Request;


class ChatMessageController extends Controller
{
    public function index()
    {
      $messages = message::with(['user'])->latest()->limit(100)->get();
      return response()->json($messages,200);
    }
}
Laerte
  • 7,013
  • 3
  • 32
  • 50
Qaim Raza
  • 33
  • 6

1 Answers1

4

In message.php, probably you forgot to add: use App\Models\User;.

So, it is trying to find User in the wrong space.

Laerte
  • 7,013
  • 3
  • 32
  • 50
  • 1
    @QaimRaza Please also observe the case of the filename. As suggested, it should be changed from `message.php` to `Message.php` to ensure it also works on a case-sensitive file system. – localheinz Aug 14 '17 at 21:12
  • 1
    Thanks @localheinz, I also changed that. – Qaim Raza Aug 14 '17 at 21:14