2

For some reason, the target controller class is not found even though it already exists in the correct path.

Route

Route::post('/send', 'MailController@send'); 

My controller path is App->Http->Controllers

Here is my controller:

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; use App\Mail\SendMail; class MailController extends Controller{ function index() { ... } function send(Request $request) { ... } } 

I have already tried composer dump-autoload. I was using laravel framework 8.0 so I have also tried to revert and use 7.24. Still, target class is not found.

2
  • change to Route::post('/send', [MailController::class, 'send']); Commented Sep 13, 2020 at 6:42
  • Where are you defining that route? Does Route::post('/send', '\App\Http\Controllers\MailController@send') work any better? Commented Sep 13, 2020 at 6:42

1 Answer 1

3

In Laravel 8, $namespace property with a value of App\Http\Controllers is set to null by default, So need to define :

Change :

Route::post('/send', 'MailController@send'); 

to,

use App\Http\Controllers\UserController; Route::post('/send', [MailController::class, 'send']); 

Or, Using string syntax :

Route::get('/users', 'App\Http\Controllers\MailController@send'); 

There is a detail answer provided by lagbox.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.