Tất cả các tuyến đường được đặt trong api.php sẽ được tiền tố/api, cũng được bernadd đề cập, có những khác biệt khác: trong liên kết này (https://mattstauffer.co/blog/routing-changes-in-laravel-5-3), bạn có thể tìm thấy sự khác biệt giữa api và web trong mã laravel :
trong App \ Providers \ RouteServiceProvider:
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
protected function mapApiRoutes()
{
Route::group([
'middleware' => ['api', 'auth:api'],
'namespace' => $this->namespace,
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
}
protected function mapWebRoutes()
{
Route::group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require base_path('routes/web.php');
});
}
trong App \ Http \ Kernel.php trong "bảo vệ $ middlewareGroups" bạn có thể thấy điều này:
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
Và: trong config \ auth.php: Trong của tập tin này Ý kiến bạn rõ ràng có thể tìm ra sự khác biệt giữa mặc định "auth" ('bảo vệ' => 'web') vs "auth: api"