公式より
前までは$namespace
を指定してない場合は
自動的にControllerのrouteに割り当てられてたけど、
v8からはデフォルトの$namespaceはnullになるよって話
だからこれまで指定できてた
Route::get('/', 'HomeController@index')->name('home.index');
といった書き方ではエラーになる
解決策
useでControllerの場所を明示してあげる
use App\Http\Controllers\HomeController;
Route::get('/', [ HomeController::class, 'index' ])->name('home.index');
もしくはフルパス指定
Route::get('/', [ App\Http\Controllers\HomeController::class, 'index' ])->name('home.index');
グループ化でnamespace設定してあげてもOK
Route::namespace('App\Http\Controllers')->group(function () {
Route::get('/', 'HomeController@index')->name('home.index');
});
In previous releases of Laravel, the
RouteServiceProvider
class contained a$namespace
property with a value ofApp\Http\Controllers
. This value of this property was used to automatically prefix controller route declarations and controller route URL generation such as when calling theaction
helper.In Laravel 8, this property is set to
null
by default. This allows your controller route declarations to use the standard PHP callable syntax, which provides better support for jumping to the controller class in many IDEs: