API或网络Laravel 5.3 [英] api or web Laravel 5.3

查看:83
本文介绍了API或网络Laravel 5.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对您来说听起来很愚蠢的问题,请原谅我.

I have a question that might sound silly to you so please forgive me.

我不确定何时使用routes/api.php文件.

I am not sure when do I use the routes/api.php file.

如果我想使用ajax从数据表中删除一条记录,我是否需要创建一个单独的控制器并将路由放置在api.php中,或者我可以使用与其他所有操作相同的控制器并将路由放置在Web中.php?

If I want to delete a record from a datatable with ajax, do I need to create a separate controller and put the route in api.php or can I use the same controller I use for everything else and put the route in web.php?

推荐答案

我不确定您是否阅读过Laravel文档或对Laravel的熟悉程度,但是在Laravel 5.3中,Web路由和api路由是分开的文件.

I'm not sure if you read the Laravel documentation or how much familiar you are with Laravel, but in Laravel 5.3 you have web routes and api routes in separate files.

您仅将api路由用于注册您的api(即,如果您正在构建Rest api服务),并且默认情况下,在此放置的所有路由都将以/api为前缀.因此,即,如果您在api文件中定义了一个路由/user,它将自动以/api为前缀,因此您的终点将是www.yourapplication.com/api/user.

You use api routes only for registering your api (ie if you are building a rest api service), and all routes placed there will be prefixed by default with /api. So ie if you define a route /user inside the api file, it will be automatically prefixed with /api, so your end point would be www.yourapplication.com/api/user.

如果您不构建Rest API服务,或者根本不使用此文件,请使用网络文件定义所有应用程序路由.

If you are not building a rest api service or anything similar dont use this file at all, use the web file for defining all of your application routes.

还考虑访问Laracast网站,因为他们对Laravel 5.3中的新更改(包括Web和api路由)进行了很好的介绍.希望对您有帮助.

Also consider visiting Laracast website, as they have a nice introduction to new changes in Laravel 5.3 including web and api routes. Hope this helps you.

这篇关于API或网络Laravel 5.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆