[英]Implementing namespaces in laravel 5.3
I am very new to Laravel 5 and PHP namespaces. 我对Laravel 5和PHP名称空间非常陌生。 I am creating an API for a website.
我正在为网站创建API。 This API will connect with other API's and create a connection with DB server.
该API将与其他API连接,并与数据库服务器建立连接。
I would like to create effective namespaces for the following structure: 我想为以下结构创建有效的名称空间:
Models:
Base.php, Category.php, Order.php, Product.php
Controllers:
OrderController.php, CategoyController.php,OrderController.php,ProductController.php
Base.php will call other API's. Base.php将调用其他API。
Category.php, Order.php & Product.php will do all the operations on category, order and product table. Category.php,Order.php和Product.php将对类别,订单和产品表进行所有操作。
While all controllers will handle the request from the routes, call their respective models or other models(if required) and returns the output in JSON form. 当所有控制器将处理来自路由的请求时,请调用其各自的模型或其他模型(如果需要)并以JSON形式返回输出。
If you require more information, please comment. 如果您需要更多信息,请发表评论。
Use the standard namespacing: 使用标准的命名空间:
- Models go under: App
- Controllers go under: App\Http\Controllers
If you are serving both web and api on the same server; 如果您在同一服务器上同时提供Web和api; hence split controllers:
因此拆分控制器:
- Web: App\Http\Controllers
- Api: App\Http\Controllers\Api
I would not recommend changing that, as that's what the other developers expect from your application. 我不建议更改此设置,因为这是其他开发人员对您的应用程序的期望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.