Bob Jones
Bob Jones

Reputation: 87

Laravel Model not being found

Hi there I am having trouble using a model within a class there error being shown is Error Class 'App\Models\RegisteredUsers' not found.

I have made sure that the namespaces match what is being used but I repeatedly get the same error.

Model code

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RegisteredUsers extends Model
{
    //
}

Controller code

<?php

namespace App\Http\Controllers;

use App\Models\RegisteredUsers;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class RegisterUser extends Controller
{
$UserObj = new RegisteredUsers();
}

The directory App/Http/Controllers/RegisterUser - controller

App/Http/Models/RegisteredUser - model

I created the model and the controller using the command line with PHP artisan. I have tried the solutions from laravel model class not found as well as Model not found in Laravel and a few laracast questions but i still get the error.

Upvotes: 0

Views: 4363

Answers (3)

Dani Fadli
Dani Fadli

Reputation: 383

With App\Models namespace in your RegsiteredUser model, the RegisteredUser.php model file must be in the app/Models/RegisteredUser.php directory. Try to move the Models folder outside the Http folder. And from now, you should never put the Models folder in the Http folder again.

Upvotes: 1

KINGSLEY OKPARA
KINGSLEY OKPARA

Reputation: 559

Your error is App/Http/Models/RegisteredUser and use App\Models\RegisteredUsers;, did you place your Models in Http?. that is not correct, the Models should be in App root directory, so you are calling the RegisteredUser in the wrong place

Upvotes: 0

vincent-h-lee
vincent-h-lee

Reputation: 66

May need to rebuild the classmap

composer dump-autoload

Upvotes: 2

Related Questions