mardi 20 novembre 2018

Class 'classname' doesn't exist

I've created a repository in Laravel for DI. I'm trying to fetch students from a certain group by group id. But I get the error that the repository class doesn't exist. I have added the repository folder to composer.json, but it hasn't fixed the problem. I have run composer update and composer dump-autoload. What am I doing wrong?

Here's my repository:

<?php
namespace App\Repositories;

use App\Models\Group;
use App\Models\Student;

class StudentRepository {
    /**
     * Get all of the students for a given group.
     *
     * @param  User  $user
     * @return Collection
     */
    public function forGroup(Group $group) {

        return Student::where('group_id', $group->id)
            ->orderBy('last_name', 'asc')
            ->get();
    }
}

The controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Respositories\StudentRepository;
use View;

class ResultsController extends Controller {

    public function __construct(StudentRepository $students) {
        $this->students = $students;
    }

    public function index() {

        return view('results.index', [
            'students' => $this->students->forGroup(),
        ]);

    }
}

composer.json:

"autoload": {
        "classmap": [
            "database/seeds",
            "database/factories",
            "app/Repositories"
        ],
        "psr-4": {
            "App\\": "app/",
            "Repositories\\" : "app/"
        }
    },



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire