Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kosala's avatar

Illuminate\ Contracts\ Container\BindingResolutionException Target class [TaskController] does not exist. Route::get('/markascompleted/{id}','TaskController@updateTaskAsCompleted');

Hi Guys,

I'm new to Laravel. I started creating a to-do app using Laravel. I get an error that says:

Illuminate\ Contracts\ Container\BindingResolutionException

Target class [TaskController] does not exist.

Route::get('/markascompleted/{id}','TaskController@updateTaskAsCompleted');

Kind regards,

Kosala.

0 likes
12 replies
tisuchi's avatar

@kosala In your routes/web.php file, you need to import the TaskController class.

use App\Http\Controllers\TaskController;


Route::get('/markascompleted/{id}','TaskController@updateTaskAsCompleted');
1 like
kosala's avatar

@tisuchi use App\Http\Controllers\TaskController; Route::get('/markascompleted/{id}','TaskController@updateTaskAsCompleted');

1 like
tisuchi's avatar

@kosala In your terminal, can you run: composer dump-autoload and then try?

1 like
kosala's avatar

@tisuchi Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

The GET method is not supported for route saveTask. Supported methods: POST.

1 like
tisuchi's avatar

@kosala Please be explicit when inform it's not working. It's totally a different error than your previous error

You should change your method type GET to POST.

For example:

use App\Http\Controllers\TaskController;

Route::post('/markascompleted/{id}','TaskController@updateTaskAsCompleted');

Suggestion: I highly recommend you to watch at least this series first to level up your understanding: https://laracasts.com/series/laravel-8-from-scratch

1 like
Snapey's avatar

use the newer route syntax

Route::get('/markascompleted/{id}', [TaskController::class, 'updateTaskAsCompleted']);

and then import the controller path at the top of the routes file.

1 like
alihaiderx736's avatar

The error message you're encountering, "Target class [TaskController] does not exist," typically occurs when Laravel cannot locate the specified controller class. Here are a few steps you can follow to troubleshoot and resolve the issue:

Verify the controller's namespace and class name: Ensure that the namespace and class name of your TaskController are correct. The namespace should match the directory structure and the class name should match the file name. For example, if your controller is located in the app/Http/Controllers directory and the file name is TaskController.php, the namespace should be App\Http\Controllers and the class name should be TaskController.

Autoload the controller class: Laravel relies on Composer's autoloading feature to load classes. Make sure that your TaskController class is properly autoloaded by Composer. To do this, open your project's composer.json file and ensure that the autoload section includes the correct mapping for your controllers. For example:

"autoload": { "psr-4": { "App\": "app/", "App\Http\Controllers\": "app/Http/Controllers/" } }

After making changes to the composer.json file, run the composer dump-autoload command in your terminal to regenerate the autoloader.

Check the file location and namespace declaration: Verify that the TaskController file is located in the correct directory (app/Http/Controllers in this case) and that the namespace declaration at the top of the file matches the actual namespace. For example:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TaskController extends Controller { // Controller methods... }

Ensure the controller extends the correct base class: In Laravel, controllers typically extend the App\Http\Controllers\Controller class. Ensure that your TaskController extends this class. For example:

use App\Http\Controllers\Controller;

class TaskController extends Controller { // Controller methods... }

Clear the route cache: If you made changes to your controller or namespace, it's a good practice to clear Laravel's route cache. Run the php artisan route:cache command in your terminal to clear the route cache. This ensures that Laravel recognizes the updated controller and namespace.

After following these steps, try accessing the route again (/markascompleted/{id}). If the issue persists, double-check the spelling and capitalization in your route declaration and ensure that the TaskController file exists in the correct directory with the correct namespace and class name.

1 like

Please or to participate in this conversation.