I am new in Laravel and working on laravel 8, Right now i am trying to change "Default routes",But i am getting following error Target class [AdminController] does not exist. Here is my code in "web.php"
use App\Http\Controllers\AdminController;
Route::get('/', 'AdminController@index')->name('admin');
Here is my "AdminController.php",how can we do this ? Thanks in advance
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index()
{
echo "Hello world";
}
}
CodePudding user response:
As per Laravel 8 release note : Routing Namespace Updates
Routing Namespace Updates
In previous releases of Laravel, the RouteServiceProvider
contained a $namespac
e property. This property's value would automatically be prefixed onto controller route definitions and calls to the action helper / URL::action
method. In Laravel 8.x,
this property is null by default. This means that no automatic namespace prefixing will be done by Laravel. Therefore, in new Laravel 8.x
applications, controller route definitions should be defined using standard PHP callable syntax:
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);
Calls to the action related methods should use the same callable syntax:
action([UserController::class, 'index']);
return Redirect::action([UserController::class, 'index']);
If you prefer Laravel 7.x
style controller route prefixing, you may simply add the $namespace
property into your application's RouteServiceProvider
.
This change only affects new Laravel 8.x applications
. Applications upgrading from Laravel 7.x
will still have the $namespace property
in their RouteServiceProvider
.