使用调用控制器的路由时未识别的控制器
Unidentified Controller when using a route that calling a controller
美好的一天,感谢您阅读这个问题
我在使用不同的参数时遇到问题,但它不起作用,这是问题代码
Route::get('/profiles','ProfilesController@index');
但是当我使用这段代码时它工作得很好
Route::get('/profiles',[ProfilesController::class, 'index']);
这是控制器
class ProfilesController extends Controller
{
public function index()
{
return profiles::all();
}
}
您需要使用完整的命名空间App\Http\Controllers\ProfilesController@index
use App\Http\Controllers\ProfilesController;
// Using PHP callable syntax...
Route::get('/profiles', [ProfilesController::class, 'index']);
// Using string syntax...
Route::get('/profiles', 'App\Http\Controllers\ProfilesController@index');
If you would like to continue using the original auto-prefixed controller routing, you can simply set the value of the $namespace
property within your RouteServiceProvider
and update the route registrations within the boot
method to use the $namespace
property.
更多信息:
https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing
美好的一天,感谢您阅读这个问题
我在使用不同的参数时遇到问题,但它不起作用,这是问题代码
Route::get('/profiles','ProfilesController@index');
但是当我使用这段代码时它工作得很好
Route::get('/profiles',[ProfilesController::class, 'index']);
这是控制器
class ProfilesController extends Controller
{
public function index()
{
return profiles::all();
}
}
您需要使用完整的命名空间App\Http\Controllers\ProfilesController@index
use App\Http\Controllers\ProfilesController;
// Using PHP callable syntax...
Route::get('/profiles', [ProfilesController::class, 'index']);
// Using string syntax...
Route::get('/profiles', 'App\Http\Controllers\ProfilesController@index');
If you would like to continue using the original auto-prefixed controller routing, you can simply set the value of the
$namespace
property within yourRouteServiceProvider
and update the route registrations within theboot
method to use the$namespace
property.
更多信息:
https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing