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
->app
->Repositories
->TodoInterface.php
->EloquentTodo.php
<?php
namespace App\Repositories;
interface TodoInterface {
public function getAll();
}
<?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();
}
}
<?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
);
}
}
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Repositories\\": "app/Repositories/"
}
},
<?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();
}
}
Route::get('my-todos','TodoController@getAllTodos');
Can somebody please help me.
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();
}
}
You may try the following commands:
composer dump-autoload
php artisan cache-clear
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
Implemented progress bar using sessionupload_progress, Worked fine for some days
How can I post a form via PHP Curl and By Pass Google Recaptcha
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
I am building a WooCommerce web-store which sells four different products