如果是一个纯粹的网站项目,只需要使用 web.php 里的路由就可以了。ajax 需要使用到的 route 也是定义在 web.php 中。
如果是一个非网页项目,例如微信小程序,Android / iOS APP 项目,或者给三方开发者提供接口,则应该使用 api.php。因为 cookie 那一套并不适用。
Web 路由使用了 web middlewareGroups 。包含类似 Session 及 CSRF 保护,而网页 ajax 同意需要 CSRF 保护。
API 路由使用了 api middlewareGroups
参考 app/Http/Kernel.php
php zend、protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
php框架laravel,\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:120000,1',
php laravel、'bindings',
],
];
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态