0

I am very new to Laravel 5 and PHP namespaces. I am creating an API for a website. This API will connect with other API's and create a connection with DB server.

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.

Category.php, Order.php & Product.php will do all the operations on category, order and product table.

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.

If you require more information, please comment.

1
  • I have answered your question, however this question has no right answer, and it's very opinionated. Commented Oct 23, 2016 at 7:20

1 Answer 1

1

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; 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.