#Laravel error Target class [Controllers\Example] does not exist.
1 messages · Page 1 of 1 (latest)
ok i did my friend
Laravel error Target class [Controllers\Example] does not exist.
and this is the code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class Sam extends Controller
{
public function showString()
{
return 'Hello';
}
}```
this is the controller file
Your issue is with routing.
and this is the route file
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 and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
route::get('second', 'Controllers\Sam@showString');
can you explain more
Well this is wrong. Why are you defining the controller action as a string? The docs don’t tell you to do that: https://laravel.com/docs/10.x/routing#the-default-route-files
wait i can't do it as a string in Laravel?
Because that hasn’t been the recommended way for more than two versions now.
You also need to take care with naming. It’s Route::get, not all-lowercase route::get
you might be right because im learning in the old version of laravel but i didn't think its gonna be an issue
becaue the course that im learing at that was before 2 years ago i think
do you recomend a new course talks about the new version of laravel
Just read the official docs.
It also has https://bootcamp.laravel.com, which takes you through building an actual application with the latest version of Laravel.
okay so i can't show a string in the new version of laravel