I want to organize Laravel code into below folder structure for the sake of easy maintenance and better grouping. I do not know whether I can do this in Laravel.
app
--order
----CustomerOrder.php
----CustomerOrderController.php
----CustomerOrderService.php
--purchasing
----PurchaseOrder.php
----PurchaseOrderController.php
----PurchaseOrderService.php
Can I modify configuration files to facilitate above hierarchy?
Laravel is a MVC-based framework. The controllers and models are placed in different folders as the documents instruct:
https://laravel.com/docs/master/structure
I suggest you organize and group your project folder structure according to Laravel document. The readability and maintenance will be much easier if everyone using the same folder structure in same framework rather than the customized structure.
Related
is it important to use the same directories for views controllers and models or you can be free to create files inside created folders and refer to them when needed
in Laravel MVC
Check docs Directory Structure
The default Laravel application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
I myself haven't tried doing my own folder structure. I would personally stick with the standard created by Laravel and follow that.
Having gone through numerous laravel tutorials and examples, i have seen source code with controllers, models and views in very different directories.
The question is, where should they go, and how does the system (which presumably requires convention) work if they are put in a different place?
E.g. the official laravel quick-start project puts them in:
app/Http/Controllers/xxxControler.php
app/Http/routes.php
resources/views/xxx.blade.php
Cant find where it has put the models.
However, the simple laravel crud master tutorial puts them here:
app/controllers/xxxControler.php
app/models/xxx.php
app/routes.php
app/views/xxx/create.blade.php
app/views/xxx/edit.blade.php
Controllers
If you look in the 5.4 documentation here it says controllers should go in app/Http/Controllers.
If this is the case, how did the latter example work (as the controller files are in the "wrong" dir, and I assume that laravel, like grails, relies on convention over configuration)?
The latter example directories seem much more logical than the official place, as a controller has nothing to do with Http - its part of the app logic.
Models
The official documentation mentions that "models typically live in the app directory". This implies they can be put put in app/models, which is good.
views
Unfortunately, the official documentation says they have to go in resources/views. Again, this would be far more logical to have views, controllers and models all being together as sub directories of app, as per the second example above. Is it possible, and advisable, to use this logical, but unofficial structure? as a beginner, I have difficulty in finding the models, views and controllers as they are put in 3 different directory paths with no obvious logic.
routes
The official documentation says that routes should go in routes/web.php. I have not found an example project using this convention - I have seen them in app/routes.php, and app/http/routes.php. Assuming its ok to put them in random places under app, how does one configure where the routes definition files go?
For Laravel version ^5.4
Controllers should be in this directory
app/Http/Controllers/xxxController.php
Models should be in this directory
app/xxx.php
Views should be in this directory
resources/views/xxx.blade.php
Routes should be in this directory
routes/web.php // for web routes
routes/api.php // for api routes
These are all recommended places to put controllers, models, views and routes. You are free to modify everything of course!
Older versions of Laravel have different places for Controllers, Models, Views and Routes. Check the documentation where they should be.
The thing is that you must recognize the Laravel version because Laravel went through many changes between years 2011 and 2016...
That link in your question for example is from year 2013 which is very old.
And I strongly recommend you to follow the Laracasts tutorials at laracasts.com
I am working in a E-Commerce Laravel project. In this project, I need to include/require/import files stored in a different server of the E-Commerce. How I can do that? What are the paths I have to include? And what are the files I have to modify?
You really do not want to do that. Even if there is a possibility to include php files from different machine, it's an awful idea. Do not do that.
If you need to get some data from another server, use RESTful API or something like this.
So I've built a front-end to a website in Codeigniter, it has public and members areas.
Now it's time to build the backend administration where staff can manage some content: http://mysite.com/admin
At first I was going to just create subfolders within my controllers, models,views and resources folders for 'admin'
I'm wondering if I should just be doing a separate installation of CI for the admin? the layouts are different, the auth is different, sure they will share the same MySQL database but the admin will have different models and controllers
Best approach?
This article by Phil will give you a better idea:
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
could i use one codeigniter framework directory to create multiple applications?
cause it seems that i have to have separate codeigniter folder instances for different applications. i want to be able to adjust some code in one place (classes that are universal) and every application i created with codeigniter will be affected.
with yii you could do this.
you can do this folder structure:
system
website-1 (your application)
----application
----index.php
website-2 (your application)
----application
----index.php
website-3 (your application)
----application
----index.php
move the 'codeigniter application folder' from the system and put it in one of you application folders.
copy the index.php file and paste inside your application folder.
In the index.php file:
YOu should have the following:
$system_folder = "../system";
$application_folder = "application";
Both Colin and Thorpe are correct.
Out of the box, sharing is not perfect. If you want to share libraries you have to put them in the system/libraries folder which makes upgrading that little bit more difficult and models cannot be shared at all.
To created a "shared" directory for libraries and models then you can use this MY_Loader.
could i use one codeigniter framework
directory to create multiple
applications?
Yes, you can create multiple applications with one CodeIgniter instance