0

I have been trying to fix this for a while now, for some reason, the program can not find the class controller, even though it is there. I have tried restarting the server, I have tried to use all kinds of uses. And it still does not work. What am I doing wrong here?

Web.php:

<?php
use App\Http\Controllers\todoListController;

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/todolist', 'todoListController@show');

The todoListController:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class todoListController extends Controller
{
  public function show() {
    $tasks = Tasks::all();

    return view('index', [
      'tasks' => $tasks,
    ]);
  }
}

2 Answers2

0

in Laravel 8 need to use use class in head and that is you are using after that for routing

Route::get('/todolist', [todoListController::class, 'show'])->name('todo-list');

if dont want to use Class than

Route::get('/todolist', 'App\Http\Controllers\todoListController@show')->name('todo-list');
Muddassir Izhar
  • 127
  • 1
  • 8
  • yes but he is not using controller class in route – Muddassir Izhar Mar 19 '21 at 10:58
  • Yes, its a typo. `Route::get('/users', 'App\Http\Controllers\todoListController@show')->name('todo-list');` – STA Mar 19 '21 at 11:09
  • In laravel 8 if you want to use controller class in route you need to use as `('/todolist', [todoListController::class, 'show'])` or if you are an old school coder than you need to specify full path of your controller `('/todolist', 'App\Http\Controllers\todoListController@show')` – Muddassir Izhar Mar 19 '21 at 11:15
0

It could be that too:

Look in the file: RouteServiceProvider.php in app/Providers and see if there is a commented line: // protected $ namespace = 'App \ Http \ Controllers'; Uncomment and try again.