1

this is my parent class which is a user class that has the main crud operations

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;    //<----------- Here


class UserController extends Controller
{
    protected $model;



    public function index()
    {
        $users = $this->model::all();
        return view('users.index', compact('users'));
    }

}

this is my child class which is one of my user roles , it have the same crud operation but it need some more functinality

<?php

namespace App\Http\Controllers;
use App\Models\Teacher;
use App\Http\Controllers\UserController;

class TeacherController extends UserController
{

    public function __construct()
    {
        $this->model = Teacher::class;
    }
}

when I try to access the route i get this error : Class name must be a valid object or a string

at :

        $users = $this->model::all();

1 Answer 1

1

Well, it seems my Laravel project used old cached routes. Just run

 php artisan route:clear

from time to time before debugging anything.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.