What are the differences between Laravel 5.3 and routing written in api.php and web.php?
PHP中文网
PHP中文网 2017-05-16 16:50:28
0
2
419

What are the differences in routing processing written in api.php and web.php in Laravel 5.3?

I want to know, if you use template rendering to create a web page, and ajax requests are also used, is it better to put the routing of this ajax request in api.php or web.php?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
Ty80

According to your description, it should obviously be placed in web.php.

Because you just have an ordinary web project, the routing in web.php uses the web middleware group.

protected $middlewareGroups = [
        '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',
        ],
    ];

If you put ajax routing in api.php without csrf protection, it is easy to cause program vulnerabilities, except for public resource requests.

api.php is used with Laravel passport to provide API services.

巴扎黑

Essentially the same.

Put it wherever you feel like it.

I think it’s better to put it in web.php. Because from your description, it doesn’t look like an API.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!