“Class App\Repositories\TodoInterface does not exist” Laravel 5.5

244
April 12, 2018, at 4:12 PM

I'm trying to implement repositories in my application structure.

I cannot find the problem here. I get the following error message:

ReflectionException Class App\Repositories\TodoInterface does not exist

My folder structure is as follows:

  ->app
    ->Repositories
         ->TodoInterface.php
         ->EloquentTodo.php

My TodoInterface.php

<?php
namespace App\Repositories;
interface TodoInterface {
public function getAll();
}

My EloquentTodo.php

<?php
namespace App\Repositories;
use App\Todo;
class EloquentTodo implements TodoInterface
{
/**
 * @var Todo
 */
private $model;
/**
 * EloquentTodo constructor.
 * @param Todo $model
 */
public function __construct(Todo $model)
{
    $this->model = $model;
}
public function getAll()
{
    return $this->model->all();
}   
}

My AppServiceProvide.php

<?php
namespace App\Providers;
use App\Repositories\EloquentTodo;
use App\Repositories\TodoInterface;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    //
}
/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    $this->app->bind(
            TodoInterface::class,
            EloquentTodo::class
        );
}
}

My composer.json

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

My TodoController.php

<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\TodoInterface;
class TodoController extends Controller
{
//
private $todo;
public function __construct(TodoInterface $todo) {
  $this->todo = $todo;
}
public function getAllTodos() {
  return $this->todo->getAll();
}
}

My Route - web.php

Route::get('my-todos','TodoController@getAllTodos');

Can somebody please help me.

Answer 1

In your EloquentTodo.php add use App\Repositories\TodoInterface;

See below

<?php
namespace App\Repositories;
use App\Todo;
use App\Repositories\TodoInterface;
class EloquentTodo implements TodoInterface
{
/**
 * @var Todo
 */
private $model;
/**
 * EloquentTodo constructor.
 * @param Todo $model
 */
public function __construct(Todo $model)
{
    $this->model = $model;
}
public function getAll()
{
    return $this->model->all();
}   
}
Answer 2

You may try the following commands:

composer dump-autoload
php artisan cache-clear
Rent Charter Buses Company
READ ALSO
Upload progress bar using session.upload_progress

Upload progress bar using session.upload_progress

Implemented progress bar using sessionupload_progress, Worked fine for some days

197
How can I post a form via PHP Curl and By Pass Google Recaptcha [on hold]

How can I post a form via PHP Curl and By Pass Google Recaptcha [on hold]

How can I post a form via PHP Curl and By Pass Google Recaptcha

152
Upload file not working through Facebook app browser

Upload file not working through Facebook app browser

The Upload file button is working fine on Chrome, Safari, Mozilla or in any native browser on mobileWhen I shared the link to Facebook and user click on the link, the page opens in the Facebook app browser but Upload file button doesn’t work

148
woocommerce unique order number or invoice number for different products

woocommerce unique order number or invoice number for different products

I am building a WooCommerce web-store which sells four different products

154