Laravel10中提示了Target *classController does not exist,為什么呢?
原因是:laravel8開始寫法變了。換成了新的寫法了
解決方法一:
在路由數(shù)組加入App\Http\Controllers\
即可。
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', [App\Http\Controllers\IndexController::class, 'index'])->name('admin.index.index');
?>
再次訪問URL,搞定。
解決方法二:文章來源:http://www.zghlxwxcb.cn/news/detail-736912.html
打開 app\Providers\RouteServiceProvider.php 修改,添加一個(gè)namespace變量文章來源地址http://www.zghlxwxcb.cn/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());
});
}
}
到了這里,關(guān)于larvel 中的api.php_Laravel 開發(fā) API的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!