Laravel10中提示了Target *classController does not exist,为什么呢?
原因是:laravel8开始写法变了。换成了新的写法了
解决方法一:
在路由数组加入App\Http\Controllers\
即可。
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', [App\Http\Controllers\IndexController::class, 'index'])->name('admin.index.index');
?>
再次访问URL,搞定。
解决方法二:文章来源:https://www.toymoban.com/news/detail-736912.html
打开 app\Providers\RouteServiceProvider.php 修改,添加一个namespace变量文章来源地址https://www.toymoban.com/news/detail-736912.html
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const HOME = '/home';
/************此处添加*START**********************/
protected $namespace = 'App\Http\\Controllers\\Api';
/************此处添加*END**********************/
/**
* Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('api')
->prefix('api')
/************此处添加*START**********************/
->namespace($this->namespace)
/************此处添加*END**********************/
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}
到了这里,关于larvel 中的api.php_Laravel 开发 API的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!